Page 1 of 1
[Solved] Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 5:32 pm
by DanCooperstock
I have both LibreOffice and OpenOffice installed, for testing. I'm not clear, when I'm instantiating a com.sun.star.ServiceManager in my program that is using the API, which I'm actually getting. I did some searching for that in my Windows Registry, and found it in a few places, some of which say OpenOffice, and some of which say LibreOffice, but all have the same CLSID (Class ID), so to me that suggests that whatever I do I'm actually running the same code!
So how do I know which I'm really accessing? Is there some method to get the name of the program?
The reason I need to know is that my program is going to be run on a computer on which I don't have control of what other applications are installed. I know that OpenOffice is installed, and it's possible that I can get them to install LibreOffice, but possible that I can't. So I need to at least know which one I'm really testing my code against (as well as which one it will run against if they do install both).
Thanks.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 7:02 pm
by Zizi64
Is there some method to get the name of the program?
Yes. There is. You can get the name and the version of the actually used AOO/LO office suite.
viewtopic.php?f=25&t=91542&p=433811
Code: Select all
REM ***** BASIC *****
Option Explicit
Function AOO_LO_Version() As String
Dim aSettings, aConfigProvider
Dim aParams2(0) As new com.sun.star.beans.PropertyValue
Dim sProvider as string
Dim sAccess as string
Dim AOO_LO_SetupVersionAboutBox as string
Dim AOO_LO_Name as string
sProvider = "com.sun.star.configuration.ConfigurationProvider"
sAccess = "com.sun.star.configuration.ConfigurationAccess"
aConfigProvider = createUnoService(sProvider)
aParams2(0).Name = "nodepath"
aParams2(0).Value = "/org.openoffice.Setup/Product"
aSettings = aConfigProvider.createInstanceWithArguments(sAccess, aParams2())
AOO_LO_SetupVersionAboutBox = aSettings.getByName("ooSetupVersionAboutBox")
AOO_LO_Name = aSettings.getByName("ooName")
AOO_LO_Version() = AOO_LO_Name & " " & AOO_LO_SetupVersionAboutBox
End Function
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 7:18 pm
by DanCooperstock
Perfect, thanks.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 7:32 pm
by DanCooperstock
Actually that raises a 2nd question. The result of that was that I was accessing OpenOffice. Given that I have both installed, is there something I can change in my code so that I end up accessing LibreOffice instead?
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 9:09 pm
by Zizi64
The current document is related to the office suite what open it. Therefore the ThisComponent and other API functions will be assigned to the actual office suite (by default) and not to an other.
What feature (and why) you want to use from the another API?
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 9:14 pm
by DanCooperstock
In my experience some of the conversions in LibreOffice are better than those in OpenOffice (like if you open one type of doc, such as a Word .docx file) and save as another type (such as HTML, with FilterName "HTML (StarWriter)" and the storeAsURL method). But so far everything I'm doing via code (starting with instantiating a com.sun.star.ServiceManager) is always using OpenOffice.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 9:22 pm
by Zizi64
It is not the best idea to edit parallel a document with two similar (but really different) office suites. You must decide what office suite you want use. I suggest you to use the LibreOffice, the latest Still version of it.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 9:25 pm
by DanCooperstock
Thanks Zizi but I think you have missed what my problem is. This is to run on a system I have little control over. They have OpenOffice installed, and may be willing to add LibreOffice (maybe not). If I can convince them to add LibreOffice, they will certainly not remove OpenOffice. So is there a way to programattically control LibreOffice when both are installed?
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 9:31 pm
by Zizi64
So is there a way to programattically control LibreOffice when both are installed?
Do you mean: you want to control the LO from the AOO?
Where the macros are stored? In the AOO, in the LO, or in the Documents?
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 10:02 pm
by DanCooperstock
I'm not running macros. I'm controlling the program through OLE from an external program (PowerBuilder application). Just like doing it from Visual Basic, JScript or whatever. So they are not stored in either application!
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 10:11 pm
by Zizi64
Yes you can control the AOO and the LO from your application by proper calling of the API functions and procedures.
Examples and descriptions:
https://www.freepascal.org/~michael/art ... office.pdf
https://wiki.openoffice.org/wiki/Using_ ... he_OOo_SDK
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 10:18 pm
by DanCooperstock
Zizi, I'm afraid you are really not understanding my problem. I have found lots of documentation about how to control OO from my application, and I have code that is working to do so, for instance to open an HTML doc and save it as PDF, and several other conversions our app needs to do.
My problem is that that code is always accessing AOO. I'd like to know how to modify it (if that is at all possible) to instead access LO, on a computer that has both installed. If that is not possible, or you don't know how, please just say so.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 10:31 pm
by RoryOF
Set your File Associations for files you wish to open to point to LibreOffice instead of OpenOffice.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Mon Oct 19, 2020 10:34 pm
by DanCooperstock
I can't imagine that will work because we aren't opening them via file associations, but rather via code in our application such as:
OLEObject iole_app, desktop, document
iole_app.ConnectToNewObject("com.sun.star.ServiceManager")
desktop = iole_app.createInstance("com.sun.star.frame.Desktop")
document = desktop.loadComponentFromURL(url, "_blank", 0, props)
Re: Am I using LibreOffice or OpenOffice API?
Posted: Tue Oct 20, 2020 7:40 am
by Zizi64
In what order did you install LibreOffice and Apache OpenOffice? A later installed software package may takes over some privileges from the one you installed earlier, and maybe the one you installed later will always start when you try to launch it from a program.
I can not see any command or reference to the AOO nor the LO in your code. It call the API without naming the office pack.
I never used a third party program to control LO / AOO ... I can not give you more help.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Tue Oct 20, 2020 4:17 pm
by DanCooperstock
I installed LO after installing AOO, but it is AOO that is coming up when I access the "com.sun.star.ServiceManager" OLE object from my application. Perhaps we have to give up on this unless someone else has a solution.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Wed Dec 07, 2022 4:19 pm
by cristigh
Hello Dan,
I have the same problem as you.
I installed OpenOffice after LibreOffice (on the same computer) and now I want to find a way to have programmatic control to create an instance of com.sun.star.ServiceManage based on the associated file type.
For example, I associated the file type ".doc" with the LibreOffice application and ".doc" with OpenOffice.
At this moment, the instance of the last installed application (OpenOffice), is always created.
My external c++ application needs to create an instance of OpenOffice/LibreOffice based on the associated file type.
Do you know how I can solve this problem?
Thanks.
Re: Am I using LibreOffice or OpenOffice API?
Posted: Wed Dec 07, 2022 8:43 pm
by JeJe
cristigh wrote: ↑Wed Dec 07, 2022 4:19 pm
For example, I associated the file type ".doc" with the LibreOffice application and ".doc" with OpenOffice.
I presume you mean something different than .doc for both of those.
If what you want is to find out what the file association is, as you're on Windows 10, maybe this will help?
https://www.codeguru.com/visual-basic/w ... ociations/
Re: Am I using LibreOffice or OpenOffice API?
Posted: Thu Dec 08, 2022 10:13 am
by cristigh
Is my mistake. I wanted to say that : "For example, I associated the file type ".doc" with the LibreOffice application and ".odt" or another file extension with OpenOffice."
I aren't opening the .doc file via file associations, but rather via code in our application such as:
CComPtr<IDispatch> pServiceManager;
hr = CoCreateInstance(CLSID("com.sun.star.ServiceManager"), NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void**)&pServiceManager);
In my case, the serviceManager interface always will be an instance of OpenOffice, since it's the latest one I have installed on my computer.
How can create an interface for LibreOffice (the CLSID is the same)?
Re: Am I using LibreOffice or OpenOffice API?
Posted: Tue Dec 20, 2022 8:43 pm
by ms777
Hi,
So is there a way to programmatically control LibreOffice when both are installed?
translated to: Can you specify to call either AO or LO from external programs?
My 90% confindence answer:
With python: yes
Using Windows ActiveX Objects: no
The code (I use powershell, C# is very similar) for the latter is something like this:
Code: Select all
[System.Reflection.Assembly]::LoadWithPartialName('cli_cppuhelper')
[System.Reflection.Assembly]::LoadWithPartialName('cli_oootypes')
[System.Reflection.Assembly]::LoadWithPartialName('cli_ure')
[System.Reflection.Assembly]::LoadWithPartialName('cli_uretypes')
$localContext = [uno.util.Bootstrap]::bootstrap()
$multiComponentFactory = [unoidl.com.sun.star.uno.XComponentContext].getMethod('getServiceManager').invoke($localContext, @())
$desktop = [unoidl.com.sun.star.lang.XMultiComponentFactory].getMethod('createInstanceWithContext').invoke($multiComponentFactory, @('com.sun.star.frame.Desktop', $localContext))
I searched for the required dll cli_cppuhelper and found only the ApacheOffice version in my Windows directory. Seems that my (newer installed) LibreOffice does not overwrite them
In python, you can specify the path to soffice.exe:
Code: Select all
import uno
import unohelper
from subprocess import Popen
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )
lo_proc = Popen('"C:\Program Files (x86)\OpenOffice 4\program\soffice.exe" -accept=socket,host=localhost,port=2002;urp;', shell=True)
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
So if you can call python from PowerBuilder you have a chance ...
Good luck,
ms777