Reputation: 11
How to place HTML text into OpenOffice spreadsheet using OpenOffice API
I have found a solution for ODT-Textdocuments.. (but nothing for a SpreadsheetDocment):
- Load odt document where we want to place HTML text.
- Goto place where you want to place HTML text.
- Save HTML text in temp file in the system (maybe it is possible without saving with http URL but I wasn't testing it).
- Insert HTML into odt following this instructions and passing URL to temp HTML file (remember about converting system path to OO path).
There where used the method: insertDocumentFromURL.
I don't know how i can use this method with a spreadsheet.. or is there another solution? For example: cellText.setHtml("....");
??? Can you or someone help me please???
Complet Code-Example for OpenOffice TextDocument:
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();
Andi
Upvotes: 1
Views: 865