Document Actions
01/30/2006
ActiveCell : the missing api
Calc API provides usefull methods to retreive current informations such as ActiveSheet or CurrentSelection.

If these api covers a lot of cases, some are not handled. Even inside a range selection, there is an active cell, usually the last selected one, depending on the way the range as been selected (from upper-left to bottom-right, bottom-left to upper-right, ...). Unfortunatelly, the CurrentSelection is only able to catch the range itself. The same problem occurs on multiple selections

This ActiveCell concept is missing and may disturb new commers from other office suite scripting like VBA.

Nevertheless, the OOo API allows to retreive this information. We can define a function that returns the cell (in OOoBasic but will work in other OOo supported languages via UNO such as Python or Java).
function ActiveCell()
'retreives viewData
ViewData = ThisComponent.CurrentController.ViewData
'many sub-separators, unify - The content remains mysterious
ViewData = join(split(ViewData,";"),"/")
ViewData = join(split(ViewData,":"),"/")
ViewData = join(split(ViewData,"+"),"/") 'handles IV65535 !
'split the string
ViewData = split(ViewData,"/")
'retreives active positions
activeCol = ViewData(6)
activeRow = ViewData(7)
'get the activeCell
activeSheet = thisComponent.CurrentController.ActiveSheet
ActiveCell = activeSheet.getCellByPosition(activeCol,activeRow)
End function
This is very tricky as the CurrentController.ViewData is poorly documented. The returned string is something like "100/60/0;0;tw:270;5/23/0/0/0/0/2/0/0/0/0;;". What does it means ?
The only way seems to look into sources as the IDL reference does not give informations
Once the information clarified, this will go to the code snippets repository.

The best would be to enrich the API with some CurrentController.ActiveCell though ...
Posted by Laurent Godard @ 01/30/2006 10:33 AM. - Categories: openoffice -  0 comments
Last modified: 01/25/2005 07:20 PM

Nuxeo Bloggers: Log in!
Nuxeo - Indesko - Nuxeo 5 Project
All content is copyrighted by their author.
CPSSkins is Copyright © 2003-2006 by Jean-Marc Orliaguet. | CPS is Copyright © 2002-2006 by Nuxeo SAS.