c# word导出之表格篇

普通的word导出 使用替换和标签的格式可以生成。但是对于word中存在的表格(table)这两种就不适用了

话不多说 直接上代码

//加载模板
Document doc = new Document(FLBNoteTemplate); 
//创建生成器对象
DocumentBuilder builder = new DocumentBuilder(doc);
//获取word中所有表格
NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
//获取第一个表格
Aspose.Words.Tables.Table table = allTables[0] as Aspose.Words.Tables.Table;
//生成多行 (word模板已存在一行)
  for (int i = 0; i < count; i++)
            {
                var roww = table.Rows[1];

                var row = roww.Clone(true);
                table.Rows.Insert(2, row);


            }
//第几个表格,第几行,第几列的数据
builder.MoveToCell(int tableIndex, int rowIndex, int columnIndex, int characterIndex);
//赋值
builder.Write("");

 

posted @ 2018-04-30 11:28  LvTwocold  阅读(421)  评论(0)    收藏  举报