OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Calc] How to deal with multi ranges selection

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
mnementh64
Newbie
Newbie


Joined: 22 May 2008
Posts: 2

PostPosted: Thu May 22, 2008 7:16 am    Post subject: [Calc] How to deal with multi ranges selection Reply with quote

Hi !

I am beginning with basic macro writing for Calc and I have a first question (critical for me) : how to deal with a user selection made of multiple disjoined ranges ?
The following classic code doesn't work :
Code:
oDesktop = createUnoService(”com.sun.star.frame.Desktop”)
oDocument = ThisComponent
oSelectedCells = oDocument.CurrentSelection
oActiveCells = oSelectedCells.RangeAddress


I would like to be able to scan each cell of each subrange and to apply it a function.

Do you know the right object (service) to use for this case ?

Thank you for your help,

Best regards,

Sylvain Caillet
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Fri May 23, 2008 1:16 am    Post subject: Reply with quote

http://www.oooforum.org/forum/viewtopic.phtml?t=60393

When operating on user selections, be prepared for any case. The following function enshures that you actuall have SheetCellRanges (unless the selection is some kind of shape). In case of a single (cell-)range it returns SheetCellRanges with one element.
Code:

'return collection of range selection(s)
'returns empty if no cells are selected
Function getCellRanges(oSelect)
   If oSelect.supportsService("com.sun.star.sheet.SheetCellRange") then
      'the intersection with itself converts range to a collection of ranges on the fly:
      oSelect = oSelect.queryIntersection(oSelect.getRangeAddress())
      getCellRanges = oSelect
   ElseIf oSelect.supportsService("com.sun.star.sheet.SheetCellRanges") then
      getCellRanges = oSelect
        Else
               REM return empty
   Endif
End Function

_________________
Rest in peace, oooforum.org
Get help on http://forum.openoffice.org
Back to top
View user's profile Send private message
mnementh64
Newbie
Newbie


Joined: 22 May 2008
Posts: 2

PostPosted: Fri May 23, 2008 1:49 am    Post subject: Reply with quote

Thank you Villeroy for this piece of code. I'll have also a deep look to the linked topic.

Sylvain
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group