如何使用 open office uno 克隆 TextTable 并将 N 个克隆的 TextTable 粘贴到原始 TextTable 下方 API
How to clone a TextTable and paste N cloned TextTable below the original TextTable using open office uno API
我有一个 XTextTable 实例。我如何才能 1) 将文本 table(包括内容和格式)克隆到新的 XTextTable 实例中,以及 2) 使用 insertTextContent 方法将新实例插入文本 table 下方?
部分代码是这样的
if (element.supportsService("com.sun.star.text.TextTable")):
table = element
tableTemplate = doc.createInstance("com.sun.star.text.TextTable")
#clone properties and content of table to tableTemplate
#get the position of insertion RANGE
for datum in data:
doc.getText().insertTextContent(RANGE,childTable,False)
#replace placeholder with datum
代码在python但我也可以翻译自Java
在我看来,您选择的解决问题的方法并不简单 - 创建新对象并克隆其属性是一个相当费力的过程。如果您需要 table 的精确副本,请尝试此算法:
Sub CloneTable
Dim oTable As Variant ' Your object
Dim oCurrentController As Variant ' Controller will copy-paste content
Dim oViewCursor As Variant ' Cursor will select some points in document
Dim oTransferable As Variant ' "Clipboard"
oTable = ThisComponent.getTextTables().getByName("Table1") ' Get your object as you can
oCurrentController = ThisComponent.getCurrentController() ' Create (get) two important tools
oViewCursor = oCurrentController.getViewCursor()
oCurrentController.select(oTable) ' Move your cursor to the beginning of the first cell of your table
oViewCursor.goLeft(1,False) ' Move the cursor to the left (no selection), position it right before the table
oViewCursor.goRight(1,True) ' Move the cursor to the right (this time with a selection), select your entire table
oTransferable = oCurrentController.getTransferable() ' Get all the information about a selected part of document
oViewCursor.goRight(0,False) ' Remove the selection from the table
Rem (otherwise the first insert will simply overwrite the existing object and you will end up with one less table than expected)
For i = 1 to 10 ' Repeat the required number of times
oCurrentController.insertTransferable(oTransferable) ' Paste an exact copy of the object at the current cursor position
Next i
End Sub
我有一个 XTextTable 实例。我如何才能 1) 将文本 table(包括内容和格式)克隆到新的 XTextTable 实例中,以及 2) 使用 insertTextContent 方法将新实例插入文本 table 下方?
部分代码是这样的
if (element.supportsService("com.sun.star.text.TextTable")):
table = element
tableTemplate = doc.createInstance("com.sun.star.text.TextTable")
#clone properties and content of table to tableTemplate
#get the position of insertion RANGE
for datum in data:
doc.getText().insertTextContent(RANGE,childTable,False)
#replace placeholder with datum
代码在python但我也可以翻译自Java
在我看来,您选择的解决问题的方法并不简单 - 创建新对象并克隆其属性是一个相当费力的过程。如果您需要 table 的精确副本,请尝试此算法:
Sub CloneTable
Dim oTable As Variant ' Your object
Dim oCurrentController As Variant ' Controller will copy-paste content
Dim oViewCursor As Variant ' Cursor will select some points in document
Dim oTransferable As Variant ' "Clipboard"
oTable = ThisComponent.getTextTables().getByName("Table1") ' Get your object as you can
oCurrentController = ThisComponent.getCurrentController() ' Create (get) two important tools
oViewCursor = oCurrentController.getViewCursor()
oCurrentController.select(oTable) ' Move your cursor to the beginning of the first cell of your table
oViewCursor.goLeft(1,False) ' Move the cursor to the left (no selection), position it right before the table
oViewCursor.goRight(1,True) ' Move the cursor to the right (this time with a selection), select your entire table
oTransferable = oCurrentController.getTransferable() ' Get all the information about a selected part of document
oViewCursor.goRight(0,False) ' Remove the selection from the table
Rem (otherwise the first insert will simply overwrite the existing object and you will end up with one less table than expected)
For i = 1 to 10 ' Repeat the required number of times
oCurrentController.insertTransferable(oTransferable) ' Paste an exact copy of the object at the current cursor position
Next i
End Sub