LibreOffice Writer:获取找到的下一个单元格的内容

LibreOffice Writer: get contents of the next cell to the found one

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

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 带有行和列参数。我该怎么做?

来自 Andrew Pitonyak, 2015 的第 7.1.2 节:

The TextRange object has a TextTable property and a Cell property. These two properties are not empty if the text range is contained in a text table 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 gave row and column numbers instead of a name. Apparently, it does not, so it is necessary to use string manipulation 解析 CellName 属性 会更容易。