[Solved] Determine suite: OpenOffice or LibreOffice

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
athena22
Posts: 3
Joined: Tue Nov 30, 2021 1:42 am

[Solved] Determine suite: OpenOffice or LibreOffice

Post by athena22 »

Hi, I am a frequent user of openffice, I immediately go to the problem, I have a file that I open with libreoffice and openoffice, some fields of the form go into error I need to know via macro with which suite I am using the file in order to set the correct code .

Code: Select all

If .... openoffice then
       ....
elseif ...... libreoffice then
    .....
end if
Thanks
Last edited by athena22 on Tue Nov 30, 2021 10:52 am, edited 1 time in total.
Open office 4.1.11
LibreOffice
Windows 10
User avatar
Lupp
Volunteer
Posts: 3755
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: info software in use

Post by Lupp »

As mostly: Look for examples and explanations in Andrew Pitonyak's "Useful Macro Information".
I have in use the following function:

Code: Select all

Function ooSetupAllDigitVersion() As String
REM This is completely from Laurent Godard as published in "Useful Macro Information" by Andrew Pitonyak.
REM It's only adapted to my style to not so much expose its migration background.
Dim structNode, providerSrv
Dim arguments(0) As New com.sun.star.beans.PropertyValue
Const providerSrvN = "com.sun.star.configuration.ConfigurationProvider"
Const structNodeN  = "com.sun.star.configuration.ConfigurationAccess"
providerSrv        = createUnoService(providerSrvN)
arguments(0).Name  = "nodepath"
arguments(0).Value = "/org.openoffice.Setup/Product"
structNode = providerSrv.createInstanceWithArguments(structNodeN, arguments())
ooSetupAllDigitVersion = structNode.ooSetupVersionAboutBox
End Function
My function only returns the up-to-4-digit-version-number.

Code: Select all

structNode.ooName
contains the "brand"..
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Determine suite: OpenOffice or LibreOffice

Post by Villeroy »

athena22 wrote:Hi, I am a frequent user of openffice, I immediately go to the problem, I have a file that I open with libreoffice and openoffice, some fields of the form go into error I need to know via macro with which suite I am using the file in order to set the correct code .
In case of a date control:

Code: Select all

If IsUnoStruct(myControl.getDate() then
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
athena22
Posts: 3
Joined: Tue Nov 30, 2021 1:42 am

Re: Determine suite: OpenOffice or LibreOffice

Post by athena22 »

Thanks to both of them, Lupp's solution is excellent. Villeroy you hit the problem, these are date fields created with openoffice and macros don't work on libreoffice. I hadn't thought of using IsUnoStruct UNO Functions.
Thank you all.
Open office 4.1.11
LibreOffice
Windows 10
User avatar
RoryOF
Moderator
Posts: 35203
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Determine suite: OpenOffice or LibreOffice

Post by RoryOF »

athena22 wrote:Thanks to both of them, Lupp's solution is excellent. Villeroy you hit the problem, these are date fields created with openoffice and macros don't work on libreoffice. I hadn't thought of using IsUnoStruct UNO Functions.
Thank you all.
Because of increasing divergence in code base between LibreOffice and OpenOffice, it is likely that _some_ macros will refuse to run on one or other, but at present, most macros should be interchangeable.
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
athena22
Posts: 3
Joined: Tue Nov 30, 2021 1:42 am

Re: [Solved] Determine suite: OpenOffice or LibreOffice

Post by athena22 »

Yes, in fact I would like to migrate to libreoffice permanently but on a pc where I installed windows 7 libreoffice I can't install it, it actually installs itself but as soon as I open it it crashes.
I am forced to use both.
Open office 4.1.11
LibreOffice
Windows 10
JeJe
Volunteer
Posts: 3132
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Determine suite: OpenOffice or LibreOffice

Post by JeJe »

Because of increasing divergence in code base between LibreOffice and OpenOffice
They both have their own (often different) set of bugs too... e.g. setPosSize works fine in OO... LO have introduced problems with it.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 35203
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Determine suite: OpenOffice or LibreOffice

Post by RoryOF »

athena22 wrote:Yes, in fact I would like to migrate to libreoffice permanently but on a pc where I installed windows 7 libreoffice I can't install it, it actually installs itself but as soon as I open it it crashes.
I am forced to use both.
I feel sure LibreOffice ought work on Windows 7: you should explore all the fixes. You may get more directed help by posting to https://ask.libreoffice.org/c/english/5

If you do post there, please leave a link here so effort is not duplicated.

Note: I do not use Windows or LibreOffice, so only surmise that LibreOffice should run on Windows 7.
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
JeJe
Volunteer
Posts: 3132
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Determine suite: OpenOffice or LibreOffice

Post by JeJe »

Its supposed to run on Windows 7 SP1.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3755
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Determine suite: OpenOffice or LibreOffice

Post by Lupp »

My answer above was given long past midnight, and therefore I omitted some statements.

1. Don't wait for educated guesses by contributors. Explain your eventual goals and reasons.
2. The code I posted only is used by myself because I often run (due to forum and bug reporting activities) different versions in parallel, and want the version shown in the title to be sure without needing to look into Help>About (I also show the generator version of the document.)
3. If the question arises concerning the alternative between two solutions to be implemented as branches in UserCode, I would prefer the way described below with an example. After all it may not be impossible that AOO will change somethiing in the relevant code / API with its next version. To ask your software the relevant question might be a good idea.

Example:

Code: Select all

SUB doMyJob()
If isREGEXfunctionAvailable() Then
  doItTheEfficientWay(....)
Else
  doItByParsingStringsWithInefficientMeans(...)
EndIf

Function isREGEXfunctionAvailable() As Boolean
On Local Error Goto fail
fa = CreateUnoService("com.sun.star.sheet.FunctionAccess")
fa.callFunction("REGEX", Array("","","",1))
isREGEXfunctionAvailable = True
fail:
End Function
@Villeroy
A myDateControl not having assigned a valid date will return Variant/Empty for myDateControl.Date. That's not an UNOStruct.
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Determine suite: OpenOffice or LibreOffice

Post by Villeroy »

Lupp wrote:A myDateControl not having assigned a valid date will return Variant/Empty for myDateControl.Date. That's not an UNOStruct.
Indeed, a LibreOffice form control has a property "Date" (but not method getDate()) which may be empty whereas a dialog's date control has method getDate and may return a struct with three zeroes when empty.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Lupp
Volunteer
Posts: 3755
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Determine suite: OpenOffice or LibreOffice

Post by Lupp »

Villeroy wrote:Indeed, a LibreOffice form control has a property "Date" (but not method getDate()) which may be empty whereas a dialog's date control has method getDate and may return a struct with three zeroes when empty.
Well, that's the kind of jokes software is playing on us, and I neither like nor easily understand.
Knowing about such mental infirmities of afflicted users, you may hint another time.
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply