zoukankan      html  css  js  c++  java
  • Aspose.Words二 基础

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

      

  • 相关阅读:
    Scrapy 概览笔记
    Python 依赖版本控制 (requirements.txt 文件生成和使用)
    Python 虚拟空间的使用
    macOS 所有版本 JDK 安装指南 (with Homebrew)
    鉴权那些事
    Java 位运算符和 int 类型的实现
    ASP.NET Core 入门教程 5、ASP.NET Core MVC 视图传值入门
    如何做好一次知识或技术分享
    ASP.NET Core 入门教程 4、ASP.NET Core MVC控制器入门
    ASP.NET Core 入门教程 3、ASP.NET Core MVC路由入门
  • 原文地址:https://www.cnblogs.com/guohu/p/9460301.html
Copyright © 2011-2022 走看看