Complex Table Example
The properties above are best illustrated by example:
As shown above, table cells can be merged horizontally. This is represented with a single table cell whose <gridSpan>
property defines the number of grid units consumed by that table cell for the current row. Consider the following fixed width table, which makes extensive use of resized and merged cells on what is actually just a seven-column grid. (The arrows point to each (invisible) vertical line of the grid and the numbers refer to the grid columns):
1 2 3 4 5 6 7
Although the table is visually complex, the standard rules apply: the first cell in the table is simply a cell which spans four grid units horizontally, as specified in the <gridSpan>
element, and whose preferred with is 2952 twips, specified in the <tcW >
element:
<w:tc> <w:tcPr> <w:tcW w:w="2952" w:type="dxa"/> <w:gridSpan w:val="4"/> </w:tcPr> <w:p/> </w:tc>
Similarly, all cells indented from the stand and end of the grid specify that ent using the <gridBefore>
and <gridAfter>
elements. For example, the XML for the second row in the table shows that that row starts three grid units into the table:
<w:tr> <w:trPr> <w:gridBefore w:val="3"/> <w:wBefore w:w="2748" w:type="dxa"/> </w:trPr> … </w:tr>
If we take this fixed width table and introduce a long string into the single cell in row 3, we see that the presence of this text does not affect cell widths:
longtextstringwithnobreakingcharacters |
If we now turn on the AutoFit property and type into the cell in row three, which spans only grid column two, we see that the algorithm for this AutoFit table causes all cells in grid column two to increase in size, proportionally decreasing the other grid columns’ size to accommodate the long non-breaking string in the last cell:
longtextstringwithnobreakingcharacters |
Each of the other grid columns was reduced, but since all columns are not at their minimum size, the table width is not increased even though the table is not yet at the page width.