Paul A Jungwirth
Paul A Jungwirth

Reputation: 24541

OpenOffice Basic Select All

Does anyone know how to select all the used cells in an OpenOffice Basic Macro? I found this other question telling how to do it with pyUno:

OpenOffice pyuno "select all"

I tried just writing the same code in Basic, but I get an error on the last line:

sheet = ThisComponent.getSheets().getByName(sheetName)
range = sheet.getCellRangeByPosition(0, 0, 0, 0)
range.gotoEndOfUsedArea(True)

The error is Property or method not found, so I guess that means the python method gotoEndOfUsedArea doesn't exist for Basic. Perhaps it is wrapping some other call I can make?

I'm on OpenOffice 3.1.1.

Upvotes: 1

Views: 2783

Answers (3)

Danfro
Danfro

Reputation: 196

The gotoEndOfUsedArea() belongs to a cursor-object, rather than to a range-object. So you have to do the Basic equivalent to

sheet = ThisComponent.getSheets().getByName(sheetName)
cursor = sheet.createCursor()
cursor.gotoEndOfUsedArea(True)
address = cursor.RangeAddress
endcol = address.EndColumn
endrow = address.EndRow
range = sheet.getCellRangeByPosition(0, 0, endcol, endrow)

I am not familiar with Basic and OpenOffice and so can not provide a solution in Basic, but I hope this python answer does still help.

Upvotes: 3

Don Briggs
Don Briggs

Reputation: 550

Let me guess, you ran this code from the Star Basic IDE when you got that error. This is actually very common. The issue is that when you run your code from the IDE, the "ThisComponent" statement returns a reference to the IDE, NOT to the spreadsheet document. And while a spreadsheet document DOES have a "getSheets" method, the macro development IDE does NOT have such a method. Hence, the error that Star Basic could not find the property or method.

Upvotes: 0

moggi
moggi

Reputation: 1486

it's a bit more complicated. sheet.getCellRangeByPosition returns a table::XCellRange whereas the gotoEndOfUsedArea is defined in sheet::XUsedAreaCursor.

But you should be able to cast between the two because they are internally implemented by the same class.

Upvotes: 0

Related Questions