【问题标题】:Duplicate last row of a table in LibreOffice using BASIC使用 BASIC 在 LibreOffice 中复制表格的最后一行
【发布时间】:2016-11-09 09:49:55
【问题描述】:

我在 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)

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

【问题讨论】:

    标签: vba libreoffice libreoffice-basic libreoffice-writer


    【解决方案1】:

    首先通过将View Cursor 移到整行上来选择整行。然后使用调度程序复制并粘贴到新行中。像这样的:

    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())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2018-09-04
      相关资源
      最近更新 更多