Tuesday June 20, 2006
OpenOffice.org API (Part 1)
Again with the help of Wouter (see yesterday's blog entry for details), I'm working on some more early experiments with the OpenOffice.org API. Here's how I've extended an application built atop the NetBeans Platform—data is retrieved from a Java DB database at start up and then, when the "Report" button is clicked, the first column in the application's table is written to a table in an Open Office Writer document:
For a small taste of what's going on behind the scenes (because, once I've stopped experimenting, a tutorial or two should come out of this), here's all the code (with comments), from the first line to the last, found under the "Report" button:
//Here we set an Open Office helper class, containing some useful methods:
OOoHelper oooHelper = new OOoHelper();
//Here we get an executable from the Options window:
settings = OfficeDocSettings.getSettings();
//Here we set the (currently hardcoded) arguments that will start Open Office in "listen mode":
String arguments = "-accept=\"socket,host=\"localhost\",port=9000;urp;StarOffice.ServiceManager\"";
try {
//Here the NetBeans process is defined for starting up Open Office:
NbProcessDescriptor process = new NbProcessDescriptor(settings.getValue(settings.KEY_EXECUTABLE),arguments);
//Here the process is executed:
process.exec();
//Here a call is made to a method that will connect the application to Open Office:
Object desktop = oooHelper.remoteConnect("localhost","9000");
//Here various Open Office objects are created:
XComponent writerComponent = oooHelper.getWriterComponent(desktop);
XTextDocument xTextDocument = oooHelper.getDocument(writerComponent);
XText xText = oooHelper.getXText(xTextDocument);
//Here we call the method that creates the table:
XTextTable xTextTable = createExampleTable(xTextDocument);
} catch (Exception ex) {
ex.printStackTrace();
}
This is all pretty cool stuff and, as Wouter wrote to me this morning: The sky is the limit.
Jun 20 2006, 11:56:03 AM PDT Permalink
Posted by Chuck Davis on June 20, 2006 at 12:34 PM PDT #
Posted by Wouter van Reeven on June 21, 2006 at 03:53 AM PDT #
Posted by Geertjan on June 21, 2006 at 08:45 AM PDT #
Posted by Geertjan on June 21, 2006 at 08:46 AM PDT #
Posted by Chuck Davis on June 21, 2006 at 09:06 AM PDT #
Posted by Geertjan on June 21, 2006 at 02:21 PM PDT #
Posted by Wouter van Reeven on June 22, 2006 at 12:13 AM PDT #
Posted by Edson Richter on June 25, 2006 at 05:17 PM PDT #


