1、目录样式
doc.Styles[Aspose.Words.StyleIdentifier.Toc1].Font.Size = 14; doc.Styles[Aspose.Words.StyleIdentifier.Toc1].Font.Bold = false; doc.Styles[Aspose.Words.StyleIdentifier.Toc1].ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Distributed; doc.Styles[Aspose.Words.StyleIdentifier.Toc1].ParagraphFormat.LeftIndent = 0; doc.Styles[Aspose.Words.StyleIdentifier.Toc1].ParagraphFormat.SpaceBefore = 0; doc.Styles[Aspose.Words.StyleIdentifier.Toc1].ParagraphFormat.SpaceAfter = 0;
2、更新目录
doc.UpdateFields();
3、首行缩进、间距
var newPara = builder.InsertParagraph(); //首行缩进 newPara.ParagraphFormat.FirstLineIndent = 24; //间距 newPara.ParagraphFormat.SpaceAfter = 0; newPara.ParagraphFormat.SpaceBefore = 0; var run = (Aspose.Words.Run)targetRun.Clone(true); run.Text = contentArray[i]; newPara.Runs.Add(run);
4、水平居中
newPara.ParagraphFormat.Alignment = ParagraphAlignment.Center;
5、表水平居中
var table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true); table.Alignment = TableAlignment.Center;
6、表格样式
//设置边框颜色 builder.CellFormat.Borders.Top.Color = System.Drawing.Color.Red; //设置边框样式 builder.CellFormat.Borders.Top.LineStyle = LineStyle.Double;
7、合并行和列
string templateFile = Server.MapPath("table_templ.doc"); string saveDocFile = Server.MapPath("table.doc"); Aspose.Words.Document doc = new Aspose.Words.Document(templateFile); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); #region 添加第一行 //第一行第一列 builder.InsertCell(); //垂直居中 builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //水平居中 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //合并行 builder.CellFormat.VerticalMerge = CellMerge.First; builder.CellFormat.HorizontalMerge = CellMerge.None; builder.Write("合并行"); //第一行第二列 builder.InsertCell(); //合并列 builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.First; builder.Write("合并列"); //第一行第三列 builder.InsertCell(); //合并列 builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.Previous; //设置边框颜色 builder.CellFormat.Borders.Top.Color = System.Drawing.Color.Red; //设置边框样式 builder.CellFormat.Borders.Top.LineStyle = LineStyle.Double; //builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single; //第一行第四列 builder.InsertCell(); //合并列 builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.None; builder.Write("第一行第四列"); builder.EndRow(); #endregion #region 添加第二行 //第二行第一列 builder.InsertCell(); builder.CellFormat.VerticalMerge = CellMerge.Previous; builder.CellFormat.HorizontalMerge = CellMerge.None; //第二行第二列 builder.InsertCell(); builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.None; builder.Write("第二行第二列"); //第二行第二列 builder.InsertCell(); builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.None; builder.Write("第二行第三列"); //第二行第二列 builder.InsertCell(); builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.None; builder.Write("第二行第四列"); builder.EndRow(); #endregion //表格水平居中 var table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true); table.Alignment = TableAlignment.Center; doc.Save(saveDocFile);