每次在使用Word的时候我们创建一个表格都希望对表格样式进行修改设置,以便表格看起来更直观和美观,在前面的文章中我们介绍了如何使用
Spire.Doc为表格设置自定义样式,然而在很多时候可能我们没有太多的时间没每个表格都设置一个详细精致的外观,那么我们就可以通过对表格设置一些内嵌的默认表格样式,这样既节约了时间,也使表格看起来都很美观。
在
Spire.Doc文档处理控件的Table类中为开发人员提供了Table.ApplyStyle()方法,开发人员可以通过该方法对已有表格快速设置样式,具体可以参考下面的部分代码:
Document doc = new Document("table.docx", FileFormat.Docx2010);
Section section = doc.Sections[0];
Table table1 = section.Tables[0] as Table;
Table table2 = section.Tables[1] as Table;
table1.ApplyStyle(DefaultTableStyle.MediumShading1Accent2);
table2.ApplyStyle(DefaultTableStyle.MediumShading2Accent1);
doc.SaveToFile("result.docx", FileFormat.Docx);