I need to find some text in the Writer table, then get contents of the cell right of the found text into the variable. Text is found successfully with this code:
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
Now I need to get contents of the right cell. As I understand, oFound
is an object of XTextRange
, and I need XCellRange
with row and column parameters. How do I do this?
From section 7.1.2 of Andrew Pitonyak, 2015:
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.
Here is example code.
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)
It would be easier if CellProperties gave row and column numbers instead of a name. Apparently, it does not, so it is necessary to use string manipulation to parse the CellName
property.