In my
previous blog concerning ActiveCell, i proposed a hack to retreive the
current column and row, based on some magic string found in
CurrentController.ViewData
We all agree that the best will be to extend the existing API. Waiting for it, here is the explanation.
Please note that in most cases, the currentSelection object should be sufficient.
This string is built in <OOoSources>/sc/source/ui/view/viewdata.cxx ScViewData::WriteUserData (thanks to noelp for pointing it). I analyzed it to see what information were stored there
so here is the magic,
but, first, as promised on the dev@api list, i put this statement
"this hack is based on an internal representation of the information not guaranted to be kept over versions"
On a new Calc file
here is the meaning identified for each portion
X2 and Y2 can also
be seen as lengths in cell number.
The information are available only if the sheet has been activated/view at least once since the file creation. In our cases, the default calc document is created with three sheets but only the first (default) has been accessed
These informations can also be found in the settings.xml file inside the calc file
<config:config-item-map-entry config:name="Feuille1">
<config:config-item config:name="CursorPositionX" config:type="int">2</config:config-item>
<config:config-item config:name="CursorPositionY" config:type="int">14</config:config-item>
<config:config-item config:name="HorizontalSplitMode" config:type="short">0</config:config-item>
<config:config-item config:name="VerticalSplitMode" config:type="short">0</config:config-item>
<config:config-item config:name="HorizontalSplitPosition" config:type="int">0</config:config-item>
<config:config-item config:name="VerticalSplitPosition" config:type="int">0</config:config-item>
<config:config-item config:name="ActiveSplitRange" config:type="short">2</config:config-item>
<config:config-item config:name="PositionLeft" config:type="int">0</config:config-item>
<config:config-item config:name="PositionRight" config:type="int">0</config:config-item>
<config:config-item config:name="PositionTop" config:type="int">0</config:config-item>
<config:config-item config:name="PositionBottom" config:type="int">0</config:config-item>
</config:config-item-map-entry>
We all agree that the best will be to extend the existing API. Waiting for it, here is the explanation.
Please note that in most cases, the currentSelection object should be sufficient.
This string is built in <OOoSources>/sc/source/ui/view/viewdata.cxx ScViewData::WriteUserData (thanks to noelp for pointing it). I analyzed it to see what information were stored there
so here is the magic,
but, first, as promised on the dev@api list, i put this statement
"this hack is based on an internal representation of the information not guaranted to be kept over versions"
On a new Calc file
print ThisComponent.CurrentController.ViewData
100/60/1;0;tw:270;17/34/0/0/0/0/2/0/0/0/0;;
here is the meaning identified for each portion
- 100/60/1;0
- zoom ratio (%) in normal view
- zoom ratio (%) in page break view
- current view mode (0|1 = normal|page break)
- Active sheet index (0 based)
- tw:270
- tw : Nammed constant TAG_TABBARWIDTH
- 270 : Width of the zone diplaying the sheets tabs (unit : pixels ?)
- 17/34/0/0/0/0/2/0/0/0/0 - For each calc sheet, semi-colon separated.
- active col (0 based)
- active row (0 based)
- split/freeze vertical (0|1|2) - 1 = split ; 2 = freeze
- split/freeze horizontal (0|1|2) - 1 = split ; 2 = freeze
- vertical position = in cell if fixed, in screen unit if frozen
- horizontal position = in cell if fixed, in screen unit if frozen
- active zone in the splitted|frozen sheet (0..3 from let to right, top to bottom)
- X1 = 0 (always ?) - the col of the upper left cell of zone 0 (upper left)
- X2 the col of the upper left cell of zone 3 (bottom right)
- Y1 = 0 (always ?) - the row of the upper left cell of zone 0 (upper left)
- Y2 the row of the upper left cell of zone 3 (bottom right)
The information are available only if the sheet has been activated/view at least once since the file creation. In our cases, the default calc document is created with three sheets but only the first (default) has been accessed
These informations can also be found in the settings.xml file inside the calc file
<config:config-item-map-entry config:name="Feuille1">
<config:config-item config:name="CursorPositionX" config:type="int">2</config:config-item>
<config:config-item config:name="CursorPositionY" config:type="int">14</config:config-item>
<config:config-item config:name="HorizontalSplitMode" config:type="short">0</config:config-item>
<config:config-item config:name="VerticalSplitMode" config:type="short">0</config:config-item>
<config:config-item config:name="HorizontalSplitPosition" config:type="int">0</config:config-item>
<config:config-item config:name="VerticalSplitPosition" config:type="int">0</config:config-item>
<config:config-item config:name="ActiveSplitRange" config:type="short">2</config:config-item>
<config:config-item config:name="PositionLeft" config:type="int">0</config:config-item>
<config:config-item config:name="PositionRight" config:type="int">0</config:config-item>
<config:config-item config:name="PositionTop" config:type="int">0</config:config-item>
<config:config-item config:name="PositionBottom" config:type="int">0</config:config-item>
</config:config-item-map-entry>
(Post originally written by Laurent Godard on the old Nuxeo blogs.)
Comments