Wordprocessing Tables
The columns of a table are defined by the <w:tblGrid> element. The <w:tblGrid> contains an element <w:gridCol> for each possible cell size (sometimes called logical columns) in the table. The number of <w:gridCol> elements needed for the table's <w:tblGrid> is determined by extending each cell's vertical borders and counting the total number of columns defined by the lines. For example, the table below has three columns and needs 3 <w:gridCol> elements in its <w:tblGrid>.
The <w:tblGrid> for this table is below:
Things become more complicated when cells are not of equal length from row to row. For example, the table below has five columns and so needs 5 <w:gridCol> elements in its <w:tblGrid> element.
The <w:tblGrid> for this table is below:
Note: The width of each cell (<w:tcW>) will equal one of the <w:gridCol> element values, or will be the sum of two or more when the table is not sized automatically.
Consider the first row in the table directly above. It looks like this:
Elements:
The <w:tblGrid> element contains one or more <w:gridCol> elements. (The <w:tblGridChange> element for tracking revisions has been omitted.)
Element | Description |
---|---|
gridCol | Specifies the details about a single grid column. The attributes are:
Reference: ECMA-376, 3rd Edition (June, 2011), Fundamentals and Markup Language Reference § 17.4.16.
|
Cell Spanning
The first cell with contents "AAA" spans the first two logical columns, so the width is the sum of the first and second <w:gridCol> element values (1638 + 1242 = 2880). Note that the <w:gridSpan> value is 2, meaning the cell spans two logical columns. The second cell with contents "BBB" spans the third and fourth logical columns, so the width is the sum of the third and fourth <w:gridCol> element values (2880 + 2178 = 5058). The <w:gridSpan> value is also 2.
The <w:gridSpan> indicates a cell horizontally spanning multiple logical cells (as defined by the <w:tblGrid>, much like the HTML colspan attribute placed on a cell. Cells can also span vertically using the <w:vMerge> element/property in a <w:tcPr> element.
The last two rows are shown below.
Related Open Document Format (ODF) Property:
A table grid is specified with <table:table-column> elements--one for each cell size appearing in the table.
If adjoining columns have the same style, then the table:number-columns-repeated attribute can be set instead of listing three separate <table:table-column> elements:
Attributes:
The most commonly used attributes are below.
Attributes | Description |
---|---|
table:default-cell-style-name | Specifies the cell style to be used if there is no value for table:style-name. |
table:style-name | Specifies a table style for the table. |
table:number-columns-repeated | Specifies the number of columns with the same style. See comments above. |
xml:id | Specifies a unique ID and is standardized by the W3C (xml-id). |
table:visibility | Specifies whether the column is visible. |
Related HTML/CSS Property:
Cell widths can be set with the width css property. Cells can span rows or columns with the rowspan and colspan attributes on a cell, respectively. Note that although there are also colgroup and col elements in HTML, they are used for grouping cells for sytlistic similarities and do not imply structural groupings like the OOXML tblGrid.
AAA | BBB | CCC |
DDD | FFF | |
GGG | HHH |