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("李斯"); 
相关推荐
itgather9 小时前
OfficeExcel — Word / Excel DLL 验证台功能介绍
c#·word·excel
云中小生9 小时前
Scrutor:.NET 依赖注入自动化的优雅实现
c#·.net
郝亚军9 小时前
Visual Studio 2022项目中的.sln是什么?
c++·c#·visual studio
jghhh019 小时前
C# 图片水印工具(支持9个位置)
数据库·microsoft·c#
咸鱼翻身小阿橙10 小时前
C# WinForms 控件学习项目
开发语言·学习·c#
JaydenAI10 小时前
[MAF预定义Agent中间件-03]FunctionInvocationDelegatingAgent:将AOP引入函数调用
ai·c#·agent·aop·maf
.NET修仙日记10 小时前
.NET 领域驱动设计:用户角色更新如何从应用服务落地到领域实体(代码拆解)
c#·.net·领域驱动设计·微软技术·角色设计
.NET修仙日记10 小时前
Scrutor:.NET 依赖注入自动化的优雅实现
c#·.net·.net core·微软技术·依赖注入·scrutor
xiaoshuaishuai810 小时前
C# Avalonia 依赖属性与WPF的区别
开发语言·c#·wpf
leo__5201 天前
C# 虚拟键盘(软键盘)实现
单片机·c#·计算机外设