Ask Your Question

How do I locate a table in a document using the SDK

asked 2019-08-16 04:25:18 +0100

tommytfc gravatar image

updated 2020-07-27 15:44:37 +0100

Alex Kemp gravatar image

Given a writer document with multiple tables in it, how do I get a specific table object and then once found how do I specify a row. I want to delete certains rows. I'm writing in but I'll take any language solution.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-08-17 21:34:44 +0100

tommytfc gravatar image

Figured it out from the SDK samples. It took some trial and error. Sorry for the VB. Given that you have an xTextDocument this will locate a table by it's name.

    Dim xTableSupplier As XTextTablesSupplier = DirectCast(xTextDocument, XTextTablesSupplier)
    Dim xTables As container.XNameAccess = xTableSupplier.getTextTables()
    Dim xTable As XTextTable
        xTable = xTables.getByName(TableName).Value
    Catch ex As container.NoSuchElementException
        Return False
    End Try

From there you can locate cells by their row column designation. This code was passed in the Row and Col value. They are expressed as you would see them in a spreadsheet. A1 is column A and row 1.

    Dim xCell As table.XCell = xTable.getCellByName(Col & Row)
    If xCell Is Nothing Then Return False
    Dim xText As XText = DirectCast(xCell, XText)
    Dim CellValue As String = xText.getString

I wanted the string value in the cell so it had to be cast as an xText. xCell returns only a double for the possible value.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-08-16 04:25:18 +0100

Seen: 41 times

Last updated: Aug 17 '19