Hi all, i’m totally new to libreOffice. I put together a script that should open a xlsx, hide a specific sheet, fit worksheets to page and export to pdf. If i manually open xlsx and run script on “ThisDocument” script works perfectly. If run from command line i get the following error on last line:
Error saving document C:\testFolder\LibreOffice\Report.xlsx:
General error. General I/O error.
From my understanding “ExportDirectToPDF” is trying to save source document with changes before exporting. I can’t understand why it fails to save and why it try saving only if source document is opened programmatically.
Thanks for helping.
This is the script:
Sub ExportToPDF(inputArg as string, outputArg as string)
dim document as object
dim dispatcher as object
inputFile = "file:///" + inputArg
outputFile = "file:///"+outputArg
MsgBox(inputFile)
MsgBox(outputFile)
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "MacroExecutionMode"
args2(0).Value = 4
args2(1).Name = "Hidden"
args2(1).Value = False
component = StarDesktop.loadComponentFromURL(inputFile, "_default",0,args2)
document = component.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
sheets = component.getSheets()
sheet = sheets.getByName("SheetToUnexport")
sheet.isVisible = False
for each sheet in sheets.ElementNames
sheet = sheets.getByName(sheet)
sheet.AutomaticPrintArea = True
next
styleFamilies = component.StyleFamilies
pageStyles = styleFamilies.getByName("PageStyles")
numStyles = pageStyles.Count
For count = 0 To numStyles - 1
defaultStyle = pageStyles(count)
defaultStyle.ScaleToPagesX = 1
rem defaultStyle.ScaleToPagesY = 1
Next count
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = outputFile
dispatcher.executeDispatch(document, ".uno:ExportDirectToPDF", "", 0, args1())
End Sub
`
This is the command line:
c:\testFolder\LibreOffice>LibreOfficePortable.exe
-headless "macro:///Standard.Module1.ExportToPDF(C:\testFolder\LibreOffice\Report.xlsx,C:\testFolder\LibreOffice\report.pdf)