Difference between revisions of "Table Style in Writerfilter"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 4: Line 4:
 
Assume there is styles.xml from docx as below:
 
Assume there is styles.xml from docx as below:
  
  <<w:style w:type="table" w:styleId="DarkList-Accent2">>
+
  w:style w:type="table" w:styleId="DarkList-Accent2"
<w:tcPr>
+
w:tcPr
<w:shd w:val="clear" w:color="auto" w:fill="C0504D" w:themeFill="accent2"/>
+
w:shd w:val="clear" w:color="auto" w:fill="C0504D" w:themeFill="accent2"/
</w:tcPr>
+
/w:tcPr
<w:tblStylePr w:type="firstRow">
+
w:tblStylePr w:type="firstRow"
<w:pPr>
+
w:pPr
<w:spacing w:before="0" w:after="0" w:line="240" w:lineRule="auto"/>
+
w:spacing w:before="0" w:after="0" w:line="240" w:lineRule="auto"/
</w:pPr>
+
/w:pPr
<w:rPr>
+
w:rPr
<w:b/>
+
w:b/
<w:bCs/>
+
w:bCs/
<w:color w:val="FFFFFF" w:themeColor="background1"/>
+
w:color w:val="FFFFFF" w:themeColor="background1"/
</w:rPr>
+
/w:rPr
<w:tblPr/>
+
w:tblPr/
<w:tcPr>
+
w:tcPr
<w:tcBorders>
+
w:tcBorders
<w:top w:val="single" w:sz="18" w:space="0" w:color="auto"/>
+
w:top w:val="single" w:sz="18" w:space="0" w:color="auto"/
<w:left w:val="nil"/>
+
w:left w:val="nil"/
<w:bottom w:val="single" w:sz="18" w:space="0" w:color="auto"/>
+
w:bottom w:val="single" w:sz="18" w:space="0" w:color="auto"/
<w:right w:val="nil"/>
+
w:right w:val="nil"/
<w:insideH w:val="nil"/>
+
w:insideH w:val="nil"/
<w:insideV w:val="nil"/>
+
w:insideV w:val="nil"/
</w:tcBorders>
+
/w:tcBorders
<w:shd w:val="clear" w:color="auto" w:fill="4BACC6" w:themeFill="accent5"/>
+
w:shd w:val="clear" w:color="auto" w:fill="4BACC6" w:themeFill="accent5"/
</w:tcPr>
+
/w:tcPr
</w:tblStylePr>
+
/w:tblStylePr
  /w:style
+
  /w:style
  
  

Revision as of 12:21, 14 August 2012

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 for whole table. So, the background color of whole table should be applied with fill color "C0504D" and its theme should be "accent2".

<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

For first row of table, below firstRow tblStylePr will be applied with fill color "4BACC6" and its theme should be "accent5". It will overwrite related color and theme from whole table 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 also up to 12 types of tblStyle here. 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? The answer is it depends on the tblLook of whole table, cnfStyle of the row and the 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>

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, even there is firstRow tblStyle exisiting in styles.xml, if tblLook forbids using firstRow, you should not expect to apply it on the row.

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