getCount method comes & goes?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Duhhh
Posts: 49
Joined: Tue Jun 03, 2008 6:10 pm
Location: USA

getCount method comes & goes?

Post by Duhhh »

I started working on a calc macro to modify cells based on user's selection. I wanted to see if it would handle a single selection as well as multiple selections. When I select more than one range at a time, ThisComponent.getCurrentSelection().getCount() returns the number I'd expect, but if there is only one range or one cell selected, I get: BASIC runtime error. Property or Method not found.

I'm puzzled - I must be using this method incorrectly, but I haven't found the "correct" way - can anyone point me to something that would set me straight?

Also, is there an "expanded class document" somewhere that would tell me all the properties and methods of an object, taking into consideration any inheritance? For example, I know that getCurrentSelection() returns a selection object - how can I get a list of all the methods and properties that are now available to me?
OOo 3.3.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: getCount method comes & goes?

Post by Villeroy »

We are talking StarBasic? The following function should help. It returns a collection of ranges or Null if some object is selected rather than cells.

Code: Select all

function getSheetCellRanges(obj)
    if obj.supportsService("com.sun.star.sheet.SheetCellRange") then
' the intersection with it's own address returns a collection with this range alone
' a single cell supports SheetCellRange as well
        getRangesSelection = obj.queryIntersection(obj.getRangeAddress())
    elif obj.supportsService("com.sun.star.sheet.SheetCellRanges") then
        getRangesSelection = obj
    else ' some kind of shape is selected
        getRangesSelection = Null
    endif
end function
A single cell supports service c.s.s.sheet.SheetCell additionally.

Don't try to write macros without having Xray installed: http://ooomacros.org/dev.php#101416
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply