B4J Question Libre/Open Office API interfacing

Num3

Active Member
Licensed User
Longtime User
Hi all,
For years (since 2006) I have been using COM components with libre/openoffice API in another programming language to execute tasks on files (text replacement, file merging, pdf printing, etc).

Basically this API opens a libre/open office instance and 'automates' actions by code, which is very useful and free to use.

Non working code example:
This example, loads a libreoffice text file and replaces 'texttoreplace' with another text.

oSM = COMate_CreateObject("com.sun.star.ServiceManager")
oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+ConvertToUrl(filename)+"', '_blank', 0, " + Str(openarray) + " as variant)")
oSrch = oDoc\GetObjectProperty("createReplaceDescriptor")
oSrch\SetProperty("SearchString ='texttoreplace'" )
oSrch\SetProperty("ReplaceString = 'REPLACED TEXT'")
oDoc\Invoke("replaceAll("+Str(oSrch)+" as COMateObject )" )

I would like to port this functionality to my B4J projects and have found there is a JAVA API too, but i really don't know how to start using it in B4J.
Can someone point me in the right direction?

Thanks.
 
Last edited:

Quandalle

Member
Licensed User
You can use the "JACOB" library which makes the interface between java world and the COM object model.
For examples do a search on the B4X forum with "JACOB".

Maybe another solution would be to use the JPOI library which is able to manipulate Word documents and does not need to have the word program installed.
For examples do a search on the B4X forum with 'JPoi word'.
 
Upvote 0

Num3

Active Member
Licensed User
Longtime User
I can use JPOI library for this purpose but with some limitations:
No support for document merging (load the content of a 'template' file into another file) and PDF printing because i don't own Excel to use the PowerShellConvertToPdf.
 
Upvote 0
Top