[Solved] Am I using LibreOffice or OpenOffice API?

Java, C++, C#, Delphi... - Using the UNO bridges
Locked
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

[Solved] Am I using LibreOffice or OpenOffice API?

Post 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.
Last edited by MrProgrammer on Wed Feb 28, 2024 7:12 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] Original questions answered Q: Get name of program?; A: Provided by Zizi64 -- MrProgrammer, forum moderator
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11412
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Am I using LibreOffice or OpenOffice API?

Post 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
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post by DanCooperstock »

Perfect, thanks.
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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?
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11412
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Am I using LibreOffice or OpenOffice API?

Post 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?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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.
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11412
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Am I using LibreOffice or OpenOffice API?

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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?
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11412
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Am I using LibreOffice or OpenOffice API?

Post 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?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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!
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11412
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Am I using LibreOffice or OpenOffice API?

Post 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
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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.
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
User avatar
RoryOF
Moderator
Posts: 34751
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Am I using LibreOffice or OpenOffice API?

Post by RoryOF »

Set your File Associations for files you wish to open to point to LibreOffice instead of OpenOffice.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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)
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11412
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Am I using LibreOffice or OpenOffice API?

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
DanCooperstock
Posts: 21
Joined: Fri Oct 16, 2020 3:57 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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.
Dan Cooperstock
OpenOffice 4.1.7 on Windows 10
cristigh
Posts: 2
Joined: Wed Dec 07, 2022 4:02 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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.
OpenOffice 4.1.7 on Windows 10
JeJe
Volunteer
Posts: 2906
Joined: Wed Mar 09, 2016 2:40 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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/
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
cristigh
Posts: 2
Joined: Wed Dec 07, 2022 4:02 pm

Re: Am I using LibreOffice or OpenOffice API?

Post 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)?
OpenOffice 4.1.7 on Windows 10
ms777
Volunteer
Posts: 188
Joined: Mon Oct 08, 2007 1:33 am

Re: Am I using LibreOffice or OpenOffice API?

Post 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
Locked