MS did a big job spreading office format worldwide. It is almost everywhere, tons, millions of files. Often it is needed to automate processing of this files. One way is to go with MS Office with VBA or OLE automation, this requires license for office and win32 system as well. Other way is to go with Open Office, which is free and reliable.
OpenOffice has nice batch processing features which no competitors have. About them I want to tell today. I would call this feature unattended usage or open office batch procesing. And it rocks.
Strong points of OpenOffice are
- Works on Windows OS family as well as Linux OS
- Can open A LOT of file formats
- It can save to many file formats
- It can run Macros, even VBA with http://go-oo.org
Typical applications are
Imagine you have to index 1000 doc document ?
Or upload excel table to site and extract all data from it ?
Or convert 10000 document to PDF ?
OpenOffice batch usage
Lets try something simple at first time, for example how to convert DOC to PDF ?
Here is example using Office 3.1 for how to convert from MS Word DOC to Adobe PDF.
Run OpenOffice and open in main menu Tools -> Macro -> Organize Dialog -> Modules -> My Macros
Click New button and choose name: Module1.
Insert this code into module and save
Sub SaveAsPDF( cFile ) Dim oPropertyValue As New com.sun.star.beans.PropertyValue cURL = ConvertToURL( cFile ) ' Open file oPropertyValue.Name = "Hidden" oPropertyValue.Value = True oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _ Array(oPropertyValue,)) ' Generate PDF name in same directory cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf" cURL = ConvertToURL( cFile ) ' Save the document using a filter. oPropertyValue.Name = "FilterName" oPropertyValue.Value = "writer_pdf_Export" oDoc.storeToURL( cURL, Array(oPropertyValue)) oDoc.close( True ) End Sub
To execute this macro in unattended mode run this command:
soffice.exe -invisible "macro:///Standard.Module1.SaveAsPDF(c:\sample.doc)"
Check c:\ it should contain sample.PDF
You can use your editor for macros, Macro files are stored XML files, for windows look for them in
c:\Document and Settings\<user>\Application Data\OpenOffice.org\3\user\basic\Standart
Same method works in Linux. You can do it on headless server.
This is simple case. If you want to dive deeper try to google for UNO.