I need to create a Python script which will take tasks from separate files (like "example_src.odt") and make an exercise book file: list tasks firstly (cell "B1"), and then list solutions (cell "B3") with tags (cell "B4"). The problem here is in embedded objects: I could just call "Text.getString()", but it copies plain text, without graphics. I made not a very short way to the following code:
Code: Select all
class WriterTest(object):
def run(self):
self.oor = OORunner()
self.desktop, self.graphicprovider = self.oor.connect()
self.testCode2()
self.oor.shutdown()
def testCode2(self):
src_url = unohelper.systemPathToFileUrl('/home/yijinger/Projects/OfficeOper/docs/example_src.odt')
result_url = unohelper.systemPathToFileUrl('/home/yijinger/Projects/OfficeOper/docs/test_result.odt')
self.src_doc = self.desktop.loadComponentFromURL(src_url, "_default", 0, ())
self.result_doc = self.desktop.loadComponentFromURL('private:factory/swriter', "_blank", 0, ())
src_all_tables = self.src_doc.getTextTables()
src_table = src_all_tables[0]
task_text = src_table.getCellByName("B3")
frameProps = (PropertyValue(Name="FrameWidthPercent", Value="100%"),)
cellContent = task_text.Text.convertToTextFrame(task_text.Text.getStart(), task_text.Text.getEnd(), frameProps)
self.src_doc.getCurrentController().select(cellContent.getText())
chunk = self.src_doc.getCurrentController().getTransferable()
result_cursor = self.result_doc.Text.createTextCursor()
result_cursor.gotoEnd(False)
self.result_doc.getCurrentController().insertTransferable(chunk)
saveArg = PropertyValue(Name="Overwrite", Value=True)
self.result_doc.storeToURL(result_url, (saveArg,))