【问题标题】:LibreOffice Writer: get contents of the next cell to the found oneLibreOffice Writer:获取找到的下一个单元格的内容
【发布时间】:2018-07-12 18:35:57
【问题描述】:

我需要在 Writer 表中找到一些文本,然后将找到的文本右侧单元格的内容放入变量中。使用此代码成功找到文本:

Sub get_contr_num
    dim oDoc as Object
    dim oFound as Object
    dim oDescriptor
    dim oCursor as Object
    oDoc = ThisComponent
    oDescriptor = oDoc.createSearchDescriptor()
    oDescriptor.SearchString = "Contract *No"
    oDescriptor.SearchRegularExpression = true
    oFound=oDoc.FindFirst(oDescriptor)
End Sub

现在我需要获取正确单元格的内容。据我了解,oFoundXTextRange 的对象,我需要带有行和列参数的XCellRange。我该怎么做?

【问题讨论】:

    标签: libreoffice openoffice.org openoffice-writer libreoffice-basic


    【解决方案1】:

    来自Andrew Pitonyak, 2015 的第 7.1.2 节:

    TextRange 对象有一个 TextTable 属性和一个 Cell 属性。 如果文本范围包含在 文本表格单元格。

    这里是示例代码。

    cellname_found = oFound.Cell.CellName
    cellname_right = Chr(Asc(Left(cellname_found, 1))+1) & Right(cellname_found, 1)
    oTable = oFound.TextTable
    oCell_right = oTable.getCellByName(cellname_right)
    

    如果CellProperties 给出行号和列号而不是名称会更容易。显然没有,所以需要使用string manipulation来解析CellName属性。

    【讨论】:

    • 谢谢,修改后有效:cellname_right = Chr(Asc(Left(cellname_found, 1))+1) + Mid(cellname_found, 2)。因为虽然列通常不会超过 A-Z 范围,但在我的例子中,行号包含多个数字。
    猜你喜欢
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 2021-04-02
    • 2010-11-20
    • 2013-06-04
    • 2021-06-07
    相关资源
    最近更新 更多