I have a requirement where I just need to open a .xlsx in libreoffice and save and close it. I am trying to see if i can do it using headless function. I am new to libreoffice and while search i thought this post ‘Save and close ods file from command line - #2 by JohnSUN’ is close to what i need. However when I try to do what this post says and execute the macro on my file using the instructions given in the post, i simply get a “>” prompt and no further information is displayed. I am not sure how to proceed. Kindly advise.
I have created a library ‘updateRefs’ and a module ‘UpdateHidden’ and have the following code within it:
Option Explicit
Sub updateAndSave(sSourcePath As String)
Dim sPath As String
Dim oDoc As Variant
Dim loadComponentProperties(0) As New com.sun.star.beans.PropertyValue
Rem Prevent screen flashing - perform file upload in "stealth mode"
loadComponentProperties(0).Name= "Hidden"
loadComponentProperties(0).Value= True
Rem We can load the spreadsheet using loadComponentFromURL().
Rem But the OpenDocument() from the Tools library does it better.
Rem Therefore, we load the Tools library:
GlobalScope.BasicLibraries.LoadLibrary("Tools")
Rem Convert the full path to the file, received in the parameter,
Rem into the correct URL:
sPath = ConvertToURL(sSourcePath)
Rem If a file with that name exists (and it may not exist):
If FileExists(sPath) Then
Rem Open spreadsheet:
oDoc = OpenDocument(sPath,loadComponentProperties)
Rem Recalculate all formulas (and update external links at the same time)
oDoc.calculateAll()
Rem Save:
oDoc.store()
Rem and close
oDoc.close(True)
EndIf
End Sub
now when i try to execute this macro from the terminal using:
libreoffice --headless --nologo "macro:///updateRefs.UpdateHidden.updateAndSave("/home/balajit/Python\ Projects/Calculate\ Capital\ Gains/testinput1.xlsx")
I get the “>” prompt.