[Solved] Identifying Multiple Selected Ranges in Calc

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
qqwasder
Posts: 4
Joined: Mon Aug 20, 2018 5:16 pm

[Solved] Identifying Multiple Selected Ranges in Calc

Post by qqwasder »

If I select A1:A2 AND A4:A5 AND A7:A8 (3 non-contiguous ranges)
and then run macro containing: msgbox ThisComponent.getCurrentSelection().getRangeAddress().Count
I get: 3
Great!

If I select A1:A2 AND A4:A5 (2 non-contiguous ranges)
and then run the same macro, I get: 2
Great!

If I select A1:A2 (a single range)
and then run the same macro again: I get: "Property or method not found: Count"
What! Why not 1???
I can see in Xray that the Count property is not exposed in the single range case, but what is the alternative to differentiate the single range case from the multiple, non-contiguous cases.

Please help me figure out how to know if non-contiguous ranges have been selected. I am getting cross-eyed reading the docs and Xray popups and I can't find the key...Thanks...
Last edited by Hagar Delest on Sun Sep 02, 2018 11:50 am, edited 1 time in total.
Reason: tagged solved
OpenOffice 4.1.5 on openSuSE 42.3
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Identifying Multiple Selected Ranges in Calc

Post by RoryOF »

Please post the full code of your macro (use

Code: Select all

 tags).
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
qqwasder
Posts: 4
Joined: Mon Aug 20, 2018 5:16 pm

Re: Identifying Multiple Selected Ranges in Calc

Post by qqwasder »

Here it is:

Function say()
msgbox ThisComponent.getCurrentSelection().getRangeAddress().Count
End Function

Any help would be appreciated...
OpenOffice 4.1.5 on openSuSE 42.3
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Identifying Multiple Selected Ranges in Calc

Post by FJCC »

Code: Select all

oSel = ThisComponent.getCurrentSelection()
If oSel.supportsService("com.sun.star.sheet.SheetCellRanges") Then
	print "multi range selection"
End If
If oSel.supportsService("com.sun.star.sheet.SheetCellRange") Then
	print "single range selection"
End If
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
qqwasder
Posts: 4
Joined: Mon Aug 20, 2018 5:16 pm

Re: Identifying Multiple Selected Ranges in Calc

Post by qqwasder »

Thank you, that did it for me. I really appreciate the guidance...
OpenOffice 4.1.5 on openSuSE 42.3
Post Reply