Nuxeo

Nuxeo Developers Blog

News from the Open Source ECM trenches

ActiveCell : the missing api

without comments

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 …

(Post originally written by Laurent Godard on the old Nuxeo blogs.)

Written by nuxeo

January 30th, 2006 at 10:33 am

Posted in Uncategorized

©2010-2012      

Built on a Wordpress using a customization of the Journalist theme.