| View previous topic :: View next topic |
| Author |
Message |
mnementh64 Newbie

Joined: 22 May 2008 Posts: 2
|
Posted: Thu May 22, 2008 7:16 am Post subject: [Calc] How to deal with multi ranges selection |
|
|
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 |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Fri May 23, 2008 1:16 am Post subject: |
|
|
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 |
|
 |
mnementh64 Newbie

Joined: 22 May 2008 Posts: 2
|
Posted: Fri May 23, 2008 1:49 am Post subject: |
|
|
Thank you Villeroy for this piece of code. I'll have also a deep look to the linked topic.
Sylvain |
|
| Back to top |
|
 |
|