1

I am trying to work with Open Office in my Java app.

Based on SDK, with extra help from bootstrapconnector.jar I successfully started empty swritter and can write to the document.

Now, I would like to open document stored in ByteArray and after some modifications save changes doc to ByteArray.

Can somebody help me doing that, please?

Here is the SDK part starting sWritter.

public static com.sun.star.text.XTextDocument openWriter(
        com.sun.star.uno.XComponentContext xContext) {
    //define variables
    com.sun.star.frame.XComponentLoader xCLoader;
    com.sun.star.text.XTextDocument xDoc = null;
    com.sun.star.lang.XComponent xComp = null;

    try {
        // get the remote office service manager
        com.sun.star.lang.XMultiComponentFactory xMCF =
                xContext.getServiceManager();

        Object oDesktop = xMCF.createInstanceWithContext(
                "com.sun.star.frame.Desktop", xContext);

        xCLoader = (com.sun.star.frame.XComponentLoader) UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
                oDesktop);
        com.sun.star.beans.PropertyValue[] szEmptyArgs =
                new com.sun.star.beans.PropertyValue[0];
        String strDoc = "private:factory/swriter";
        xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs);
        xDoc = (com.sun.star.text.XTextDocument) UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
                xComp);

    } catch (Exception e) {
        System.err.println(" Exception " + e);
        e.printStackTrace(System.err);
    }
    return xDoc;
}

as you can see there is a method loadComponentFromURL.

I saw somewhere else, in the OOoBeanViewer, that it is possible to read and write doc to ByteArray, however I don't know how to achieve that without officebean.jar which I don't want to use in my project.

Thanks for your comments and hints.

norbi771
  • 814
  • 2
  • 12
  • 29

0 Answers0