如何使用OpenOffice API将HTML文本放入OpenOffice电子表格

如何使用OpenOffice API将HTML文本放入OpenOffice电子表格,html,openoffice-calc,openoffice-api,Html,Openoffice Calc,Openoffice Api,如何使用OpenOffice API将HTML文本放入OpenOffice电子表格 我已经找到了ODT文本文档的解决方案。。但电子表格文档没有: 将odt文档加载到要放置HTML文本的位置。 转到要放置HTML文本的位置。 在系统中的临时文件中保存HTML文本可能不需要使用http URL保存,但我没有测试它。 按照以下说明将HTML插入odt,并将URL传递给临时HTML文件,记住如何将系统路径转换为OO路径。 这里使用了方法:insertDocumentFromURL 我不知道如何在电子表格

如何使用OpenOffice API将HTML文本放入OpenOffice电子表格

我已经找到了ODT文本文档的解决方案。。但电子表格文档没有:

将odt文档加载到要放置HTML文本的位置。 转到要放置HTML文本的位置。 在系统中的临时文件中保存HTML文本可能不需要使用http URL保存,但我没有测试它。 按照以下说明将HTML插入odt,并将URL传递给临时HTML文件,记住如何将系统路径转换为OO路径。 这里使用了方法:insertDocumentFromURL

我不知道如何在电子表格中使用这种方法。。还是有其他解决办法?例如:cellText.setHtml。。。。;???你或谁能帮我一下吗

OpenOffice文本文档的完整代码示例:

安迪

IDocumentService documentService = OOConnection.getDocumentService();
            IDocument document = documentService.constructNewDocument(IDocument.WRITER, new DocumentDescriptor());

            textDocument = (ITextDocument) document;
            String htmlText = "<P></P>" + "<P>Paragraph1</P>" + "NOA HTML Insert Test" + "<b>Bold</b>"
                    + "<H1>Header 1</H1>" + "<P>Paragraph2</P>" + "<CENTER>Center</CENTER>" + "<TABLE>"
                    + "<TR><TD bgcolor=#336699>Cell 1</TD><TD bgcolor=#663399>Cell 2</TD></TR>"
                    + "<TR><TD bgcolor=#123456>the third cell</TD><TD bgcolor=#654321>Cell 4</TD></TR>" + "</TABLE>";
            textDocument.getTextService().getText().setText(htmlText);
            textDocument.getPersistenceService().export(new FileOutputStream("C:/SfH/html.html"), new TextFilter());

            XController xController = textDocument.getXTextDocument().getCurrentController();
            XTextViewCursorSupplier xTextViewCursorSupplier = (XTextViewCursorSupplier) UnoRuntime.queryInterface(
                    XTextViewCursorSupplier.class, xController);
            XTextViewCursor xViewCursor = xTextViewCursorSupplier.getViewCursor();
            XTextCursor xTextCursor = xViewCursor.getText().createTextCursorByRange(xViewCursor.getStart());
            XDocumentInsertable xDocumentInsertable = (XDocumentInsertable) UnoRuntime.queryInterface(
                    XDocumentInsertable.class, xTextCursor);

            xDocumentInsertable.insertDocumentFromURL(
                    URLAdapter.adaptURL(new File("C:/SfH/html.html").getAbsolutePath()), new PropertyValue[0]);
            textDocument.update();