Aspose Words如何实现对Word中表格的格式化

作者:控件中国网   出处:控件中国网   2015-08-26 09:46:29   阅读:10

在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");

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat