pdx:addTable

Inserts a table into a Word document.

Description

Element definition

This element allows the insertion of a table into your Word document.

You may:

  • Create tables with complex row and col spans.
  • Insert in each single table cell:
    • plain text,
    • rich text,
    • nested tables,
    • lists,
    • images,
    • charts
    • footnotes and endnotes or
    • any combination of all the above.
  • Style the table as a whole and/or its individual rows and cells: set, for example, global properties like borders and margins that can be overridden for each table cell.
  • You may position the table by its own or make it float so the surrounding text will wrap around it.

Like in the standard MS Word interface, tables, by default, have a black border in every cell. If you want a borderless table you should specify the border option to none in tableProperties

Attributes and sub-elements

tableData

These entries may be:

  • a simple string of text,
  • a WordFragment element or

The first option is only valid for very simple tables that only contain plain text.

The WordFragments are only needed if we want to insert images, charts, nested tables or complex paragraphs.

key Description
value The text to be inserted (string) or a Word fragment if we want to insert complex paragraphs, images, nested tables...
backgroundColor Hexadecimal color value: 'FF0000', '000000'...
border Border type: none, single, double, dashed, threeDEngrave, threeDEmboss, outset, inset... This value can be overridden for each side with the use 'borderTop', 'borderRight', 'borderBottom' and 'borderLeft' properties.
borderColor Hexadecimal color value: 'FF0000', '000000'... This value can be overridden for each side with the use of 'borderTopColor', 'borderRightColor', 'borderBottomColor' and 'borderLeftColor' properties.
borderSpacing Border spacing in points. This value can be overridden for each side with the use of 'borderTopSpacing', 'borderRightSpacing', 'borderBottomSpacing' and 'borderLeftSpacing' properties.
borderWidth Border size in eigths of a point. This value can be overridden for each side with the use of 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth' and 'borderLeftWidth' properties.
cellMargin An integer or an array with keys: top, right, bottom and left. The values are given in twentieths of a point.
colspan The col span of that particular table cell.
fitText If true fits the text to the size of the cell.
noWrap If true text does not wrap.
rowspan The row span of that particular table cell.
textDirection Sets the direction of the flow of text. Available values are: lr (default), tbRl and btLr.
vAlign Vertical align of text: top, center, both or bottom.
width Preferred cell width in twentieths of a point (twips).

tableProperties

This is an array including all general table options (some of them may be overridden by row or cell properties).

The possible keys and values of this array are:

key Description
bidi Sets to 'true' for right to left languages (default value is 'false').
border Border type: none, single, double, dashed, threeDEngrave, threeDEmboss, outset, inset... By default the border type is single. You should select none for borderless tables.
borderColor Hexadecimal color value: 'FF0000', '000000'...
borderSpacing Border spacing in points.
borderWidth Border size in eigths of a point.
borderSettings Possible values are: all, outside, inside. if all (default value) the border styles apply to all table borders. If the value is set to outside or inside the border styles will only apply to the outside or inside boreders respectively.
cantSplitRows Sets global row split properties (can be overriden or set for individual rows by rowProperties).
cellMargin General cell margins for the whole table. An integer or an array with keys: top, right, bottom and left. The values are given in twentieths of a point.
cellSpacing Separation among cells. Given in twentieths of a point (twips).
columnWidths An integer or a zero-based array with the widths of each column in twentieths of a point.
conditionalFormatting This option let us control which formatting conditions declared in the corresponding table style should be applied. The possible keys and values are:
  • 'firstRow' (boolean) first table row conditional formatting
  • 'lastRow' (boolean) last table row conditional formatting
  • 'firstCol' (boolean) first table column conditional formatting
  • 'lastCol' (boolean) last table column conditional formatting
  • 'noHBand' (boolean) do not apply row banding conditional formatting
  • 'noVBand' (boolean) do not apply column banding conditional formatting
The default values are: firstRow (true), firstCol (true), noVBand (true) and all other false.
float With the following keys and values:
  • 'align' (string) possible values are: left, center, right, outside, inside
  • 'textMarginTop' (int) in twentieths of a point
  • 'textMarginRight' (int) in twentieths of a point
  • 'textMarginBottom' (int) in twentieths of a point
  • 'textMarginLeft' (int) in twentieths of a point
font Font family: 'Arial', Calibri'...
indent Left table margin in twentieths of a point (twips).
tableAlign Table alignment. Possible values are: center, left or right.
tableLayout Possible values are: fixed or autofit (default). Set it to 'fixed' only if you do not want Word to handle the best possible width.
tableStyle Word table style id (you may run parseStyles element to check for the available styles in xmldocx or your particular template).
tableWidth Its possible keys and values are:
  • 'type' (pct, dxa) pct if the value refers to percentage and dxa if the value is given in twentieths of a point (twips)
  • 'value' (int)
textProperties It may include any of the paragraph properties of the addText element so you can completely customize the properies of the the text content of the table.

rowProperties

This is an array of arrays (one for each row we want to customize) including all available row options.

The possible keys and values of each of these arrays are:

key Description
cantSplit If true the row cannot split across pages.
height Exact row height in twentieths of a point (twips)
minHeight Minimum row height in twentieths of a point (twips).
tableHeader If true, and the table splits across pages, this row repeats at the beginning of each new page.
Code samples
#Example 1

config.xml

content.xml

settings.xml

The resulting Word document looks like: