I am using a .vba script to convert .xls to .html assume the /tmp/m.xls is input xls then the command soffice -calc -nologo -nofirststartwizard -view -norestore -headless -nolockcheck -unaccept=all 'macro:///Standard.Module1.SaveAsHTML("/tmp/m.xls","/tmp/m.xls.html","HTML (StarCalc)")' convert m.xls to m.xls.html just fine. The problem is: in case the file m.xls has, for example HTML content inside then: 1. if there exist an "openoffice open window" then the command above give a dialogue "Filter not found" (because it cannot import .html as .xls) DESPITE THE OPTION -headless if I click OK - it exits & fails to convert, as it should be. But -headless should not give no dialogue at all. 2. This became much more problematic if there is no open openoffice window. Then the command above NEVER EXITS,just hangs forever. Probably because it expects a click on "Filter not found", and there is no chance to click. This create a very serious problem in using openoffice as batch format converter, because if input format is wrong - soffice never exit.
Created attachment 435637 [details] code for batch export copy the content to Module1 (inside Tools->Macro)
1. Yes, OOo is always a single process, so if there is a non-headless instance already running, then a second headless is not created, so the -headless option doesn't affect the already running OOo that executes the macro. 2. No, it isn't stuck on a "Filter not found" dialog. Its the document is opened in writer successfully, the store to url fails, so it jumps to the ConversionError and the document isn't closed, so its still there idling. Try this replacement code.
Created attachment 435749 [details] replacement code This might work better
Caolan, Thanks a lot. The code you suggested works fine with invalid content inside input file. The only problem left - if input file does not exist at all. Then I get an error (and window opened) and stuck at oDoc.close( True ) I tries the handling below ---------------------- Sub SaveAsHTML(iFile, oFile, convertername) ON ERROR GOTO ConversionError ......conversion code.... ConversionError: ON ERROR Resume Next oDoc.close( True ) 'exit sub End Sub ------------------------------ but the result is the same - if input file does not exist - the new window is opened and oDoc.close( True ) is highlited. I can do a workaround to test file existence outside of OO, but would much prefer to handle oDoc.close( True ) errors in basic.
I fixed mentioned problem this way, is it correct? Sub SaveAsHTML(iFile as String, oFile as String, convertername as String) ON ERROR Resume Next Dim oDoc As Object oDoc = StarDesktop.loadComponentFromURL(ConvertToURL(iFile), "_blank", 0, Array(MakePropertyValue("Hidden",True),MakePropertyValue("ReadOnly",true),)) if IsObject( oDoc ) Then oDoc.storeToURL(ConvertToURL(oFile), Array(MakePropertyValue("FilterName",convertername),)) oDoc.close( True ) EndIf 'exit sub End Sub
looks fairly reasonable