0

我在 ODT 文档中有一个命名表,并希望将包含所有内容的最后一行复制到新行(上图)中,然后替换此副本中的一些值。

我已经在 Word/VBA 中为 DOCX 完成了此操作:

Dim tbl As Table
Dim rowNew As Row

Set tbl = ActiveDocument.Tables(1)
Set rowNew = tbl.Rows.Add(tbl.Rows(tbl.Rows.Count))
rowNew.Range.FormattedText = tbl.Rows(tbl.Rows.Count).Range.FormattedText
'~~~> This is required as the above code inserts a blank row in between
tbl.Rows(tbl.Rows.Count - 1).Delete
rowNew.Select
Selection.Find.Execute FindText:="xx*", ReplaceWith:="bar", MatchWildcards:=True
Selection.Collapse

这在 LibreOffice 中也可以吗?到目前为止,我有:

DIM tbl As Variant
DIM row As Variant
tbl =  ThisComponent.getTextTables().getByIndex(0)
row = tbl.getRows().getByIndex(tbl.getRows().getCount()-1)

如何选择和复制整并在新行上运行搜索和替换?提示:该行可能包含其他对象,例如子表。

4

1 回答 1

1

首先通过将视图光标移动到整行上来选择整行。然后使用调度程序复制并粘贴到新行中。像这样的东西:

oVC.goRight(3, True)  'Extend the selection.
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:InsertRowsAfter", "", 0, Array())
oVC.goDown(1, False)  'Move to the new row.
oVC.goLeft(2, False)  'Move to the first column.
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
于 2016-11-11T06:31:26.580 回答