Table Style in Writerfilter

From Apache OpenOffice Wiki
Revision as of 05:32, 15 August 2012 by Bjcheny (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Table style refers to table's border styles, text's font properties, background color. It is mainly decided by styles.xml from Office Open XML.


Assume there is styles.xml from docx as below:

  < w:style w:type="table" w:styleId="DarkList-Accent2">
     < w:tcPr>
        < w:shd w:val="clear" w:color="auto" w:fill="C0504D" w:themeFill="accent2"/>
     < /w:tcPr>
     < w:tblStylePr w:type="firstRow">
        < w:pPr>
           < w:spacing w:before="0" w:after="0" w:line="240" w:lineRule="auto"/>
        < /w:pPr>
        < w:rPr>
           < w:b/>
           < w:bCs/>
           < w:color w:val="FFFFFF" w:themeColor="background1"/>
        < /w:rPr>
        < w:tblPr/>
        < w:tcPr>
           < w:tcBorders>
              < w:top w:val="single" w:sz="18" w:space="0" w:color="auto"/>
              < w:left w:val="nil"/>
              < w:bottom w:val="single" w:sz="18" w:space="0" w:color="auto"/>
              < w:right w:val="nil"/>
              < w:insideH w:val="nil"/>
              < w:insideV w:val="nil"/>
           < /w:tcBorders>
           < w:shd w:val="clear" w:color="auto" w:fill="4BACC6" w:themeFill="accent5"/>
        < /w:tcPr>
     < /w:tblStylePr>
  < /w:style>


Background Color

Include cell/row/table's background color.

wholeTable

The w:tcPr under w:style is applied on the whole table. So, the background color of whole table should be applied with fill color "C0504D" and its theme should be "accent2" from theme.xml.

  < w:style w:type="table" w:styleId="DarkList-Accent2">
     < w:tcPr>
        < w:shd w:val="clear" w:color="auto" w:fill="C0504D" w:themeFill="accent2"/>
     < /w:tcPr>
  < /w:style>

firstRow and others

Below firstRow tblStylePr means application with fill color "4BACC6" and its theme should be "accent5" for row. It will overwrite related color and theme from wholeTable mentioned above.

     < w:tblStylePr w:type="firstRow">
        < w:tcPr>
           < w:shd w:val="clear" w:color="auto" w:fill="4BACC6" w:themeFill="accent5"/>
        < /w:tcPr>
     < /w:tblStylePr>

There can be up to 12 types of tblStyle here at most. They are:

  • firstRow #first row
  • lastRow #last row
  • firstCol #first column
  • lastCol #last column
  • band1Vert #odd column
  • band2Vert #even column
  • band1Horz #odd row
  • band2Horz #even row
  • neCell #last cell in first row
  • nwCell #first cell in first row
  • seCell #last cell in last row
  • swCell #first cell in last row

tblLook and cnfStyle

With above basic knowledge, we now can get further. For example, for the first cell in first row, which tblStyle should take effect, firstRow, firstCol, nwCell? Which one has highest priority? It depends on the tblLook in tblPr for whole table, and cnfStyle in trPr for row and tcPr for cell.

Take below cell in a table from document.xml for example:

  < w:tbl>
     < w:tblPr>
        < w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
     < /w:tblPr>
     < w:tr w:rsidR="001662F7" w:rsidTr="00C76FCB">
        < w:trPr>
           < w:cnfStyle w:val="100000000000" w:firstRow="1" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:oddVBand="0" w:evenVBand="0" w:oddHBand="0" w:evenHBand="0" w:firstRowFirstColumn="0" w:firstRowLastColumn="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0"/>
        < /w:trPr>
        < w:tc>
           < w:tcPr>
              < w:cnfStyle w:val="001000000100" w:firstRow="0" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:oddVBand="0" w:evenVBand="0" w:oddHBand="0" w:evenHBand="0" w:firstRowFirstColumn="1" w:firstRowLastColumn="0" w:lastRowFirstColumn="0" w:lastRowLastColumn="0"/>
              < w:tcW w:w="4261" w:type="dxa"/>
           < /w:tcPr>
        < /w:tc>
     < /w:tr>
  < /w:tbl>

tblLook

Based on description from Office Open XML, tblLook decides whether following tblStyle can be applied on table or not:

  • firstRow
  • lastRow
  • firstCol
  • lastCol
  • band1Vert
  • band2Vert
  • band1Horz
  • band2Horz

That means, firstRow won't be applied, if tblLook forbids it, even though there is firstRow tblStyle exisiting in styles.xml. In fact, it's shown as below UI in MS Office 2010.

Checkbox.jpg

cnfStyle

Assume tblLook allows all types of tblStyle. Then, let's turn to cnfStyle. It specifies which kind of tblStyle can be applied for current row and cell. Not all first row can be applied with firstRow tblStyle, unless its cnfStyle tells this. It's similar case for cell, check its cnfStyle.

Sometimes, the cnfStyle for cell will specify more than that from row. How to decide it? There is a rule from Office Open XML:

  • wholeTable
  • band1Horz band2Horz
  • band1Vert band2Vert
  • firstCol lastCol
  • firstRow lastRow
  • neCell nwCell seCell swCell

That means neCell has higher priority than firstRow. The firstRow and lastRow tblStyle have higher priority than firstCol and lastCol. And so on.


Font Properties

Including font size, bold, italic, color, strike-through, underline, and so on.

Border Styles

Including border's style, color, and so on.

Personal tools