Aspose.Words指定位置插入table

如果在创建书签,然后在书签位置插入表格,会出现格式错乱,在单元格位置里面有一个表格,不符合实际使用。正确做法是复制模板文件里面的表格行,然后插入若干行。

如图标记红色位置插入动态数据行,是先复制标记位置的行,然后预先插入若干空行,最后来填充数据。

csharp 复制代码
//读取word
string wordTempPath = Path.Combine(AppContext.BaseDirectory, "WordTemplate", "template_report.docx");

Aspose.Words.Document doc = new Aspose.Words.Document(wordTempPath);
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
  
  //找到表格
  var nodeList = doc.GetChildNodes(nodeType: NodeType.Table, true);
  var table = nodeList[0] as Aspose.Words.Tables.Table;
  
  for (int i = 0; i < 16; i++)
  {
      //复制一行
      var rowNew = table.Rows[5].Clone(true);
      table.Rows.Insert(6 + i, rowNew);
  }
 
//找到指定位置单元格,写入数据
builder.MoveToCell(0, 5, 0, 0);
builder.Write("测试数据");

builder.MoveToCell(0, 5, 1, 0);
builder.Write("李斯"); 
相关推荐
唐青枫13 小时前
对象到底住在哪里?C#.NET 托管堆从分配、GC 到内存排查
c#·.net
fogota15 小时前
Emoji与Segoe MDL2 Assets的比较
c#·wpf
灸木16 小时前
C# 多线程与异步
c#
鱼听禅20 小时前
C# 学习笔记-使用 类型化客户端搭建HTTP客户端服务
学习·http·c#·工厂方法模式
geovindu21 小时前
CSharp:Condition Variable Pattern
后端·设计模式·c#·.net·.netcore·条件变量模式·同步型模式
淡海水1 天前
11-03-Unity-List-T-和Dictionary-TKey-TValue-的性能调优实战
算法·unity·c#·list·dictionary
fogota1 天前
C# 如何调用系统图标
c#·.net
△曉風殘月〆1 天前
.NET是什么?为什么要选择.NET?
c#·.net·.net core·clr
fogota1 天前
C# WPF 按钮加载字体图标 / 动物头像
c#·.net·wpf
fogota1 天前
C# WPF 按钮加载系统图标 / 动物头像
c#·.net·wpf