I’ve been trying to automate OpenOffice from Ruby to carry out a batch format conversion of approximately 100 documents. I’ve researched a fair amount on the web, especially here, here and here, but I’m still having problems.
Specifically all works until I try and save a document using parameters (to tell OpenOffice to use an output filter), at which point the OLE Bridge is giving an error.
If anyone reading this has found and cured a similar problem I’d be interested in your thoughts. Code snip follows:
Ignore the escaping of the ” signs – this seems to be some oddity of my WordPress installation…
# oo tests require 'win32ole' $serviceManager = WIN32OLE.new("com.sun.star.ServiceManager") $desktop = $serviceManager.createInstance("com.sun.star.frame.Desktop") def newWriterDocument() document = $desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, []) document end def test() filter = "writer_pdf_Export" fprops = makeProperties("FilterName" => filter) document = newWriterDocument text = document.GetText cursor = text.createTextCursor text.insertString(cursor, "Hello World", 0) oURL = "file:///c|/test.pdf" document.storeAsUrl(oURL, fprops) # this line fails with OLE error #store a document in standard format - document.storeAsUrl(oURL, []) - works end def makeProperty(name, value) property = $serviceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue") property["Name"] = name property["Value"] = value property end def makeProperties(hash) properties = [] hash.each { | key, value | properties < < makeProperty(key, value) } properties end begin test rescue ensure end
Question also posted to OpenOffice.org forum.
OpenOffice.org forum came up with the answer:
Replace
document.storeAsUrl(oURL, fprops) # this line fails with OLE error
with
document.storeToUrl(oURL, fprops) # this line works!