Spire.Doc 13.9.10 现已发布。该版本公开了几个用于精细化文档样式控制的核心接口。此外还支持移除文档样式和添加预置表格样式等。详情如下。
新功能:
- 公开 ICharacterStyle、IListStyle和 ITableStyle 等核心接口,支持更精细的文档样式控制。
- Style接口移除了CharacterFormat属性,此属性分别在TableStyle,ParagraphStyle和CharacterStyle接口中进行实现。
- Style接口提供RemoveSelf()的方法,支持移除样式。
- TableStyle 实现 ITableStyle 接口。同时新增 TableConditionalStyle、TableConditionalStyleCollection 和 TableConditionalStyleType 类型,支持对表格的奇偶行、奇偶列等条件格式进行精细化控制。
- Table.TableStyleName 属性已标记为过时,建议使用 table.Format.StyleName替换。增加Table.Format.Style 和 Table.ApplyStyle(ITableStyle) 应用表格样式。
- TableFormat类提供了Style,StyleOptions,StyleName 属性以及 TableStyleOptions 枚举。
- Document类新增AddStyle(DefaultTableStyle builtinStyle) 方法,支持添加预置表格样式。
IStyle style = document.Styles.FindByName("Normal");
if (style != null && style is ICharacterStyle)
{
ICharacterStyle cStyle = style as ICharacterStyle;
cStyle.CharacterFormat.FontName = "cambria";
cStyle.CharacterFormat.FontSize = 14;
cStyle.CharacterFormat.Bold = true;
cStyle.CharacterFormat.TextColor = Color.FromArgb(42, 123, 136);
}
string pStyleName = "testStyle";
Document document = new Document();
ParagraphStyle pStyle = (ParagraphStyle)document.Styles.Add(StyleType.ParagraphStyle, pStyleName);
pStyle.CharacterFormat.FontName = "Calibri";
pStyle.CharacterFormat.FontSize = 16;
pStyle.CharacterFormat.Bold = true;
pStyle.CharacterFormat.TextColor = Color.DarkRed;
Section section = document.AddSection();
Paragraph para = section.AddParagraph();
para.ApplyStyle(pStyle);
para.AppendText("Hello world!");
Style firstParaStyle = document.FirstSection.Body.FirstParagraph.Format.Style;
document.SaveToFile(outputDocxFile1, FileFormat.Docx);
document.Styles[pStyleName].RemoveSelf();
document.SaveToFile(outputDocxFile2, FileFormat.Docx);
Document doc = new Document();
Section section = doc.AddSection();
Table table = section.AddTable();
table.ResetCells(15, 4);
for (int i = 0; i < 15; i++)
{
TableRow row = table.Rows[i];
for (int j = 0; j < 4; j++)
{
TableCell cell = row.Cells[j];
cell.AddParagraph().AppendText(string.Format("{0} column.", (j % 2 == 0 ? "Even" : "Odd")));
cell.AddParagraph().AppendText(string.Format("Row banding {0}", (i % 3 == 0 ? "start" : "continuation")));
}
}
TableStyle tableStyle = (TableStyle)doc.Styles.Add(StyleType.TableStyle, "TestTableStyle1");
tableStyle.Borders.Color = Color.Black;
tableStyle.Borders.BorderType = BorderStyle.Double;
tableStyle.RowStripe = 3;
tableStyle.ConditionalStyles[TableConditionalStyleType.OddRowStripe].Shading.BackgroundPatternColor = Color.LightBlue;
tableStyle.ConditionalStyles[TableConditionalStyleType.EvenRowStripe].Shading.BackgroundPatternColor = Color.LightCyan;
tableStyle.ColumnStripe = 1;
tableStyle.ConditionalStyles[TableConditionalStyleType.EvenColumnStripe].Shading.BackgroundPatternColor = Color.LightPink;
table.ApplyStyle(tableStyle);
table.Format.StyleOptions = table.Format.StyleOptions | TableStyleOptions.ColumnStripe;
doc.SaveToFile(outputDocxFile1, FileFormat.Docx);
Document doc = new Document();
Section section = doc.AddSection();
TableStyle tableStyle = (TableStyle)doc.Styles.Add(StyleType.TableStyle, "TestTableStyle1");
tableStyle.HorizontalAlignment = RowAlignment.Center;
tableStyle.Borders.Color = Color.Blue;
tableStyle.Borders.BorderType = BorderStyle.Single;
Table table = section.AddTable();
table.ResetCells(1, 1);
table.Rows[0].Cells[0].AddParagraph().AppendText("Aligned to the center of the page");
table.PreferredWidth = PreferredWidth.FromPoints(300);
table.ApplyStyle(tableStyle);
section.AddParagraph().AppendText(" ");
tableStyle = (TableStyle)doc.Styles.Add(StyleType.TableStyle, "TestTableStyle2");
tableStyle.LeftIndent = 55;
tableStyle.Borders.Color = Color.Green;
tableStyle.Borders.BorderType = BorderStyle.Single;
table = section.AddTable();
table.ResetCells(1, 1);
table.Rows[0].Cells[0].AddParagraph().AppendText("Aligned according to left indent");
table.PreferredWidth = PreferredWidth.FromPoints(300);
table.Format.Style = tableStyle;
doc.SaveToFile(outputDocxFile1, FileFormat.Docx);
Document doc = new Document();
Section section = doc.AddSection();
Table table = section.AddTable();
table.ResetCells(15, 4);
for (int i = 0; i < 15; i++)
{
TableRow row = table.Rows[i];
for (int j = 0; j < 4; j++)
{
TableCell cell = row.Cells[j];
cell.AddParagraph().AppendText(string.Format("{0} column.", (j % 2 == 0 ? "Even" : "Odd")));
cell.AddParagraph().AppendText(string.Format("Row banding {0}", (i % 2 == 0 ? "Even" : "Odd")));
}
}
TableStyle tableStyle = doc.AddStyle(DefaultTableStyle.LightListAccent3);
table.ApplyStyle(tableStyle);
doc.SaveToFile(outputDocxFile1, FileFormat.Docx);
获取Spire.Doc 13.9.10,请点击: