如何从JAVA中的ByteArray加载OpenOffice

时间:2013-05-24 12:40:27

标签: java bytearray openoffice-writer

我正在尝试在我的Java应用程序中使用Open Office。

基于SDK,在bootstrapconnector.jar的额外帮助下,我成功启动了空swritter并可以写入文档。

现在,我想打开存储在ByteArray中的文档,经过一些修改后将更改文档保存到ByteArray。

有人可以帮我这么做吗?

这是启动sWritter的SDK部分。

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;
}

你可以看到有一个方法loadComponentFromURL。

我在OOoBeanViewer中看到了其他地方,它可以读取和写入ByteArray的文档,但是我不知道如何在没有officebean.jar的情况下实现这一点,我不想在我的项目中使用它。

感谢您的意见和提示。

0 个答案:

没有答案