Ask Your Question
0

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)
Doc.CurrentController.Select(Col)   

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
0

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

pierre-yves samyn gravatar image

Hi

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
oDoc.currentController.Select(oCursor)
oFrame = oDoc.CurrentController.Frame

oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oFrame, ".uno:EntireColumn", "", 0, Array())

end sub

See

Regards

edit flag offensive delete link more
0

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)
    ThisComponent.getCurrentController().select(oCellRangeByPosition)
End Sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 435 times

Last updated: Jun 08 '16