zoukankan      html  css  js  c++  java
  • Aspose.Words三 创建表格

    创建表格,实现合并行、和并列、表居中、表格水平和垂直居中、设置单元格边框颜色和样式。

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

     

  • 相关阅读:
    MySQL:解决脏读问题
    MySQL:隔离性问题(脏读)&回滚演示
    MySQL: Mysql 事务隔离级别
    MySQL:数据库事务
    GRE Vocabulary:sedulous
    MySQL:SQL约束
    GRE Vocabulary:pall
    MySQL:DQL操作单表
    MySQL: DQL 查询表中数据
    MySQL:DML操作 表中数据
  • 原文地址:https://www.cnblogs.com/guohu/p/9460045.html
Copyright © 2011-2022 走看看