Ask Your Question

Select Text Table Columns

asked 2016-06-08 05:20:54 +0200

macroman gravatar image

Hopefully a simple question, but I cannot seem to find an answer in the documentation or online:

I want to be able to select particular rows/columns within Writer document text tables.

In theory the macro should look something like this:

sub test

Doc = ThisComponent
Col = Doc.getTextTables(0).getColumns.getbyindex(3)

end sub

However, I am currently getting a BASIC runtime error:

Property or method not found: getColumns.

(Same goes for 'getRows')

The command seems to work if I create a table from scratch, but will not work on existing tables??

Thanks in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-06-08 08:18:42 +0200

pierre-yves samyn gravatar image


I would do something like this:

option explicit

sub PysSelectCol

dim oDoc as object, oTable as object, oCell as object
dim oCursor as object, oFrame as object, oDispatcher as object

oDoc = ThisComponent

oTable = oDoc.getTextTables.GetByIndex(0)
oCell = oTable.getCellByName("D1")

oCursor = oCell.createTextCursor
oFrame = oDoc.CurrentController.Frame

oDispatcher = createUnoService("")
oDispatcher.executeDispatch(oFrame, ".uno:EntireColumn", "", 0, Array())

end sub



edit flag offensive delete link more

answered 2016-06-08 10:46:31 +0200

JohnSUN gravatar image

Or - without DispatchHelper - you can select range of cells:

Sub SelectColumnTextTable(Optional nCol As Long)
Dim oTextTable As Variant
Dim nLastColumn As Long
Dim nLastRow As Long
Dim oCellRangeByPosition As Variant
Dim oCurrentController As Variant
    oTextTable = ThisComponent.getTextTables().getByIndex(0)
    nLastColumn = oTextTable.getColumns().getCount() - 1
    If IsMissing(nCol) Then nCol = nLastColumn
    If (nCol<0) or (nCol>nLastColumn) Then Exit Sub
    nLastRow = oTextTable.getRows().getCount() - 1

    oCellRangeByPosition = oTextTable.getCellRangeByPosition(nCol, 0, nCol, nLastRow)
End Sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-06-08 05:20:54 +0200

Seen: 435 times

Last updated: Jun 08 '16