DrawingML Tables - Structure
A table is defined within a <a:tbl> element, which itself contains a definition of the table structure (within a <a:tblGrid> element), table properties (within a <a:tblPr> element), and content (within one or more <a:tr> table row elements).
The columns of a table are defined by the <a:tblGrid> element. The <a:tblGrid> contains an element <a:gridCol> for each possible cell size (sometimes called logical columns) in the table. The number of <a:gridCol> elements needed for the table's <a:tblGrid> is determined by extending each cell's vertical borders and counting the total number of columns defined by the lines. For example, a table which has three columns with no cells that are merged needs 3 <a:gridCol> elements in its <a:tblGrid>.
Things become more complicated when cells are not of equal length from row to row. For example, the table below has four possible or logical columns and so needs 4 <a:gridCol> elements in its <a:tblGrid> element.
The <a:tblGrid> for this table is below.
The <a:tblGrid> element contains one or more <a:gridCol> elements -- one for each column. The <a:gridCol> element has one attribute w which specifies the width of the column in EMUs.
The table shown above contains examples of cells that span both vertically and horizontally. For example, cells 1-1, 1-2, 2-1, and 2-2 have been merged and contain the text "Merged vertically and horizontally. Cell spanning in drawingML tables is indicated differently that it is in WordprocesingML tables. First, in wordprocessingML tables cells that have been merged do not appear in the XML for the row. That is, there are only as many cell elements in the row as there are cells that appear visually. In drawingML tables, every row contains as many <a:tc> elements as there are logical columns or <a:gridCol> elements. Second, cell spanning in wordprocessingML is indicated with elements (<w:gridSpan> and <w:vMerge>). However, in drawingML cell spanning is indicated with attributes of <a:tc>.
Tables contains rows or <a:tr> elements. Each <a:tr> element contains the same number of <a:tc> elements are there are <a:gridCol> elements. If two or more cells are merged horizontally, then the first cell contains a gridSpan attribute specifying the number of cells that are merged. Subsequent cells that are merged contain a hMerge attribute set to true (hMerge="1"). If two or more cells are merged vertically, then the first cell (that is, the cell containing the content) contains a rowSpan attribute specifying the number of rows that a cell spans. Corresponding cells in rows below that cell (that is, the cells that have been merged with the cell above) contain a vMerge attribute set to true (vMerge="1").
The sample below shows the XML for the table above. The cells that are spanned vertically or horizontally have matching colors for their related attributes (gridSpan and hMerge="1", or rowSpan and vMerge).