How to add color scales to ODF?

Markus Mohrhard markus.mohrhard at googlemail.com
Wed May 9 18:02:43 PDT 2012


Hey,

I just reached a state where I can think about adding support for
color scales into ODF. Normally this would not be such a big deal but
for color scales we face several problems.

Color scales are a form of conditional formatting but our current
conditional formatting system is based on styles where color scales (
and data bars ) don't fit in. The problem is now that conditional
formatting is part of the styles in ODF and applied to a cell through
a style. I have the same problem internally but there I was able to
circumvent that problem till now by implementing a own set of data
structures for color scales.

The current structure of a conditional format in ods looks like:

<style:style style:name="ce1" style:family="table-cell"
style:parent-style-name="Default">
  <style:map style:condition="cell-content()=1"
style:apply-style-name="Untitled1"
style:base-cell-address="Sheet1.D5"/>
  <style:map style:condition="cell-content()<0"
style:apply-style-name="Untitled2"
style:base-cell-address="Sheet1.D5"/>
  <style:map style:condition="cell-content-is-between(2,3)"
style:apply-style-name="Untitled3"
style:base-cell-address="Sheet1.D5"/>
</style:style>

Now we have color scales which are no longer bound to styles because
they calculate the correct formatting information based on the value
of the cell. I would not want to add them to the existing style based
system because they don't fit into there. We will need to add
different conditions for them and different ways to represent them.

In OOXML normal conditional formats are represented in the
[sheetx].xml file and refer to formatting changes in the styles
section. Color scales however are represented in the same structure
but contain all their information as sub elements. The structure of
the attached test file is:

<conditionalFormatting sqref="C2:D5">
  <cfRule type="colorScale" priority="1">
    <colorScale>
      <cfvo type="num" val="0"/>
      <cfvo type="num" val="10"/>
      <color rgb="FF63BE7B"/>
      <color rgb="FFFFEF9C"/>
    </colorScale>
  </cfRule>
</conditionalFormatting>

I'm open for suggestions how I can add this sanely to ods. I would
like to support as much from MSO 2010's color scale feature as
possible but have no idea yet what I can achieve in the remaining 4
weeks.

Regards,
Markus

Attached is my test document ( the only document that I support right
now ) and a screenshot showing how it is rendered right now. I know
that it is not rendered correctly right now.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SimpleColorScale.xlsx
Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Size: 8440 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120510/ddb7c32a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: color_scales.png
Type: image/png
Size: 6200 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120510/ddb7c32a/attachment.png>


More information about the LibreOffice mailing list