1

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?

Michael
  • 5,095
  • 2
  • 13
  • 35

1 Answers1

1

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.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • 1
    Thanks, it worked after modifying: `cellname_right = Chr(Asc(Left(cellname_found, 1))+1) + Mid(cellname_found, 2)`. Because while columns don't often exceed the range A-Z, row numbers in my case contain more than one digit. – Michael Jul 12 '18 at 20:42