Applying Formatting on the Table Level
To apply formatting to a table you can use the properties available on the corresponding Table node. A visual view of table formatting features in Microsoft Word and their corresponding properties in Aspose.Words are given below.
Below example shows how to apply a outline border to a table.
Below example shows how to build a table with all borders enabled (grid).
Applying Formatting on the Row Level
Below example shows how to modify formatting of a table row.
Applying Formatting on the Cell Level
Below example shows how to modify formatting of a table cell.
Following code example shows how to set the amount of space (in points) to add to the left/top/right/bottom of the contents of cell.
Specifying Row Heights
The height of a table row is controlled using height and height rule properties. These can be set differently for each row in the table which allows for wide control over the height of each row. In Aspose.Words these are represented by the RowFormat.Height and RowFormat.HeightRule properties of the given Row.
This is the default height rule given to a new row. Technically this means that no height rule is defined. The row is sized to fit the largest content within the cells of the row.
With this setting the height of the row will grow to accommodate the content of the row, but will never be smaller than the specified size in RowFormat.Height .
The size of the row is set exactly to the value found in RowFormat.Height and does not grow to fit content.
Below example shows how to create a table that contains a single cell and apply row formatting.
Applying Borders and Shading
Borders and shading can be applied either table wide using Table.setBorder(int,int,double,java.awt.Color,boolean), Table.setBorders(int,double,java.awt.Color) and Table.setShading(int,java.awt.Color,java.awt.Color) or to particular cells only by using CellFormat.getBorders() and CellFormat.getShading(). Additionally borders can be set on a row by using RowFormat.getBorders(), however shading cannot be applied in this way.
Below example shows how to format table and cell with different borders and shadings.
Get Distance between Table and Surrounding Text
Below example shows how to get distance between table and its surrounding text.
How to Get the Table's Alignment
If the table's text wrapping is Around, you can get the table's horizontal and vertical alignment using Table.getRelativeHorizontalAlignment() and Table.getRelativeVerticalAlignment() properties. In other case, you can get table's inline alignment using Table.getAlignment() property. Below example shows how to get the table's alignment.
Get Position of Floating Table
Below example shows how to get the position of floating table.
Working with Alternative Text of Table
The title and description of table provides alternative text-based representations of the information contained in table. MS Word allows to set this information (Right-click the table, click Table Properties, click the Alt Text tab, and then set the title and description of table). With Aspose.Words you can achieve this by using Table.Title and Table.Description properties. These properties are meaningful for ISO/IEC 29500 compliant DOCX documents. When saved to pre-ISO/IEC 29500 formats, these properties are ignored. Below code example shows how to set table's title and description properties.
Allow Spacing Between Cells
MS Word does not add any additional space between the cells in a table by default. You can find this option in table's properties in MS Word. You can get or set "Allow spacing between cells" option using Table.AllowCellSpacing property. Below code example shows how to set space between cells.