在Word中可以对表格进行各种设置,进行相关的格式化,Aspose Words也可以通过代码完全对表格对象进行控制和格式化,几乎所有Word可以实现的功能,Aspose Words也同样可以做到,具体的格式化可以参考下面的代码:
下面的事例为表格设置外边框:
Document doc = new Document(MyDir + "Table.EmptyTable.doc");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
// Align the table to the center of the page.
table.Alignment = TableAlignment.Center;
// Clear any existing borders from the table.
table.ClearBorders();
// Set a green border around the table but not inside.
table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, Color.Green, true);
// Fill the cells with a light green solid color.
table.SetShading(TextureIndex.TextureSolid, Color.LightGreen, Color.Empty);
doc.Save(MyDir + "Table.SetOutlineBorders Out.doc");
下面的事例是构建一个带所有外边框的表格:
Document doc = new Document(MyDir + "Table.EmptyTable.doc");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
// Clear any existing borders from the table.
table.ClearBorders();
// Set a green border around and inside the table.
table.SetBorders(LineStyle.Single, 1.5, Color.Green);
doc.Save(MyDir + "Table.SetAllBorders Out.doc");