addTable

addTable

BASIC / ADVANCED / PREMIUM

Inserts a table into a Word document.

Description
public void addTable(ArrayList<ArrayList<OptionsTableData>> tableData)
public void addTable(ArrayList<ArrayList<OptionsTableData>> tableData, OptionsTableProperties tableProperties)
public void addTable(ArrayList<ArrayList<OptionsTableData>> tableData, OptionsTableProperties tableProperties, ArrayList<OptionsTableRow> rowProperties)

This method 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
    • footnotes and endnotes
    • any combination of all of 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 overriden 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.

Parameters

tableData

This is an ArrayList. Each entry of this ArrayList contains the content and style needed to render that particular table cell.

Option Type Description
value WordFragment The content to be inserted.
backgroundColor String Hexadecimal color value: "FF0000", "000000"...
border String 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 String Hexadecimal color value: "FF0000", "000000"... This value can be overridden for each side with the use of "borderTopColor", "borderRightColor", "borderBottomColor" and "borderLeftColor" properties.
borderSpacing Integer Border spacing in points. This value can be overridden for each side with the use of "borderTopSpacing", "borderRightSpacing", "borderBottomSpacing" and "borderLeftSpacing" properties.
borderWidth Integer 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 HashMap<String, String> A HashMap: top, right, bottom and left. The values are given in twentieths of a point.
colspan Integer The col span of that particular table cell.
fitText Boolean If true fits the text to the size of the cell.
noWrap Boolean If true text does not wrap.
rowspan Integer The row span of that particular table cell.
textDirection String Sets the direction of the flow of text. Available values are: lr (default), tbRl and btLr.
vAlign String Vertical align of text: top, center, both or bottom.
width Integer Preferred cell width in twentieths of a point (twips).

tableProperties

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

  • type (pct, dxa) pct if the value refers to percentage and dxa if the value is given in twentieths of a point (twips).
  • value.
Option Type Description
bidi Boolean Sets to true for right to left languages.
border String 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 String Hexadecimal color value: 'FF0000', '000000'...
borderSpacing Integer Border spacing in points.
borderWidth Integer Border size in eigths of a point.
borderSettings String 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 Boolean Sets global row split properties (can be overriden or set for individual rows by rowProperties).
cellMargin HashMap<String, String> 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 Integer Separation among cells. Given in twentieths of a point (twips).
columnWidths Integer An integer with the widths of each column in twentieths of a point.
conditionalFormatting HashMap<String, Boolean> This option lets you control which formatting conditions declared in the corresponding table style should be applied. The possible keys and values are:
  • firstRow first table row conditional formatting.
  • lastRow last table row conditional formatting.
  • firstCol first table column conditional formatting.
  • lastCol last table column conditional formatting.
  • noHBand does not apply row banding conditional formatting.
  • noVBand does not apply column banding conditional formatting.
float HashMap<String, String> With the following keys and values:
  • align possible values are: left, center, right, outside, inside.
  • textMarginTop in twentieths of a point.
  • textMarginRight in twentieths of a point.
  • textMarginBottom in twentieths of a point.
  • textMarginLeft in twentieths of a point.
font String Font family: "Arial", "Calibri"...
indent Integer Left table margin in twentieths of a point (twips).
tableAlign String Table alignment. Possible values are: center, left or right.
tableLayout String 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 String Word table style id (you may run parseStyles method to check for the available styles in Javadocx or your particular template).
tableWidth HashMap<String, String>

rowProperties

This is an ArrayList (one position for each row you want to customize) including all available row options.

Option Type Description
cantSplit Boolean If true the row can not split across pages.
height Integer Exact row height in twentieths of a point (twips).
minHeight Integer Minimum row height in twentieths of a point (twips).
tableHeader Boolean If true, and the table splits across pages, this row repeats at the beginning of each new page.
Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like:

Example #3

The resulting Word document looks like: