JSON API - addTable

addTable

PREMIUM TRIAL / ADVANCED

Inserts a table into a Word document.

Note

You are reading the JSON API documentation. For the PHP API method please go to addTable.

JSON data
Key Description
value The text to be inserted (string) or a WordFragment if you 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.
caption
  • "align" alignment of the caption
  • "bookmarkName" set a custom bookmark name
  • "color" text color
  • "fontSize" text size in half-points
  • "keepNext" keep in the same page the current paragraph with next paragraph. Default as false
  • "label" set a custom label (Table by default)
  • "lineSpacing" text line spacing
  • "position" below (default), above
  • "pStyle" custom style name applied to the paragraph. This option overwrites the "styleName" option as custom paragraph style
  • "showLabel" show default value Table
  • "styleName" allow setting a custom style name, useful to generate table of figures based on style names
  • "text" text of the caption
  • "wrapTextInBookmarks" wrap text content between bookmarks. Default as true
cellMargin An integer or an object 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).
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 object 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 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.
The default values are: firstRow (true), firstCol (true), noVBand (true) and all other false.
descr Description value.
descrTitle Title description value.
float With the following keys and values:
  • "align" left, center, right, outside, inside.
  • "horzAnchor" margin (default), page, text
  • "textMarginTop" in twentieths of a point.
  • "textMarginRight" in twentieths of a point.
  • "textMarginBottom" in twentieths of a point.
  • "textMarginLeft" in twentieths of a point.
  • "tblpXSpec" center, inside, left, outside, right. Default as align value
  • "tblpYSpec" center, inside (default), bottom, outside, inline, top
  • "vertAnchor" margin, page, text (default)
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 method to check for the available styles in phpdocx 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"
textProperties It may include any of the paragraph properties of the addText method so you can completely customize the properies of the text content of the table.
cantSplit If true the row can not 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

Example #2

Example #3

Release notes
  • phpdocx 18.0:
    • new action.