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("李斯"); 
相关推荐
longxiaozhang612 小时前
C# Array类:数组其实没那么难
开发语言·c#
longxiaozhang615 小时前
C#运算符重载:让对象也能使用“加减乘除”
开发语言·c#
花落人散处16 小时前
C# 核心编程知识点总结:网络编程、委托与事件、异步编程与LINQ
c#
fl17683119 小时前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf
CoderIsArt21 小时前
OPC UA 完整介绍、官网、C# 简单使用
开发语言·c#
界面开发小八哥21 小时前
界面控件DevExpress XAF v26.1新版亮点——AI Agent Skills
ai·c#·跨平台·devexpress·ui开发·xaf
csdn_aspnet21 小时前
C# 高效便利的处理数据
开发语言·windows·c#
淡海水1 天前
03-02-线性-List-T-动态数组布局-扩容与操作成本
数据结构·windows·c#·list·编译·clr·机器码
csdn_aspnet1 天前
C# 在逗号分割的字符串中判断是否包含指定字符
c#·正则·linq·string·regex·contains
宝桥南山1 天前
Blazor Web Assembly - 体验一下Authentication State从Server共享给Client
microsoft·微软·c#·asp.net·.net·.netcore