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("李斯"); 
相关推荐
半亩码田8 小时前
C#转Python第5.1篇:异步编程:asyncio vs async/await,语法相似但机制不同
开发语言·python·c#
阿华田5128 小时前
Java 类加载冲突实战:解决 is not an instance of
c#·linq
samble18 小时前
从零搭建灌装监控系统(十七):LiveCharts 实时温度曲线
c#·wpf·mvvm·modbus·工业控制
淡海水1 天前
02-07-原理篇-GC暂停时间的本质
开发语言·unity·c#·gc·暂停时间
小羊没烦恼!1 天前
OS X 上使用.NET开发应用程序
开发语言·前端·数据库·人工智能·c#·策略模式
Behavior1 天前
Unity 7.0 Alpha 拆解:编辑器干掉 Mono 换 CoreCLR
c#·unity3d·游戏开发
淡海水1 天前
02-06-原理篇-增量式GC与并发GC
算法·unity·c#·并发·gc·增量
Vertira1 天前
C# 函数封装成 DLL,
开发语言·c#
浅尝辄止;1 天前
设计模式在HIS/LIS医疗系统中的完整实践指南(C#版)
开发语言·设计模式·c#
kimloner2 天前
开源一个 376KB 的 Windows 桌面小工具:便签 + 截图标注 + OCR + 待办提醒(C# / WinForms)
windows·开源·c#·ocr·winforms