Using PB 2019, I'm trying to use OpenOffice through OLE to open an Excel doc and save it as CSV. (Yes, I can do that Excel, but this is for a situation where OpenOffice is available but Excel isn't.)
I'm running into two problems: the SaveAsURL (or SaveToURL) always fails with an OpenOffice IOError, and the OpenOffice application never closes (as seen on Task Manager).
Here's my code (in a function taking asFilename as its argument):
iole_app = CREATE OLEObject
OLEobject desktop, prop, props, document
string fixedFilename, saveFilename
if iole_app.ConnectToNewObject("com.sun.star.ServiceManager") <> 0 THEN
MessageBox('Test', 'Unable to start OpenOffice.',Exclamation!)
desktop = iole_app.createInstance("com.sun.star.frame.Desktop")
prop = iole_app.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
prop.Name = "Hidden"
prop.Value = TRUE // don't want to show UI
props = prop
fixedFilename = "file:///" + asFilename
gf_replace_all(fixedFilename, "\", "/") // replaces the 2nd arg with the 3rd throughout the 1st arg
document = desktop.loadComponentFromURL(fixedFilename, "_blank", 0, props)
pos = LastPos(Lower(fixedFilename), ".xls")
if pos = 0 then
MessageBox("Test", "Cannot find .xls in filename")
saveFilename = Mid(fixedFilename, 1, pos) + "csv"
props.Name = "FilterName"
props.Value = "scalc: Text - txt - csv (StarCalc)"
props = iole_app.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
props.Name = "Overwrite"
props.Value = TRUE
catch (OLERuntimeError ex)
MessageBox("Test", "Error " + ex.description + " saving to " + saveFilename + "~n~n: " + ex.text)
I know I am doing overkill on the DESTROYs and also SetNull, but I'm trying everything. If I change the property "Hidden" used in the properties sent to loadComponentFromURL() to FALSE (or omit it, since FALSE is the default) the application does close after the code finishes.
But document.storeToURL (or the alternative storeAsURL) always throws a com.sun.star.task.ErrorCodeIOException, with no further helpful details. I have checked that the file URL it is supplying is OK, and I know that the directory the file is in is writeable.
Any bright ideas? Thanks.