ドキュメントの挿入
外部のファイルをドキュメントに挿入します。 テキストカーソルやビューカーソルの insertDocumentFromURL メソッドを利用します。 Sub insertDocument_1 oDoc = ThisComponent oText = oDoc.getText() oCursor = oText.createTextCursor() oCursor.insertDocumentFromURL("file:///C:/usr/2.odt",Array()) End Sub 引数はドキュメントを読み込む際の loadComponentFromURL メソッドのものと同じものを利用します。が、http://extensions.openoffice.org/issues/show_bug.cgi?id=83449 オプションが動かないため、InputStream などを利用してドキュメント挿入が動きません (issue 修正待ち)。 2.4 以降では InputStream から insertDocument メソッドでドキュメントを挿入できます。 Sub insertDocument_2 sHtml = "<html><body>Formatted HTML <b>BOLD</b>.</body></html>" oTemp = CreateUnoService("com.sun.star.io.TempFile") oOut = oTemp.getOutputStream() oTxtOut = CreateUnoService("com.sun.star.io.TextOutputStream") oTxtOut.setOutputStream(oOut) oTxtOut.writeString(sHtml) oTxtOut.flush() oIn = oTemp.getInputStream() ' insert data to a new writer document from the InputStream oNewDoc = StarDesktop.loadComponentFromURL( _ "private:factory/swriter", "_blank", 0, Array() ) oController = oNewDoc.getCurrentController() oViewCursor = oController.getViewCursor() oText = oNewDoc.getText() oCursor = oText.createTextCursorByRange(oViewCursor.getEnd()) Dim args(1) As New com.sun.star.beans.PropertyValue args(0).Name = "InputStream" args(0).Value = oIn args(1).Name = "FilterName" args(1).Value = "writer_web_HTML"'"writer_Rich_Text_Format" oCursor.insertDocumentFromURL("",args) End Sub |