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("李斯"); 
相关推荐
hez20101 天前
.NET 11 Runtime Async 详解
c#·.net·.net core
猿长大人1 天前
C# | Serilog 新手入门
开发语言·c#·.net·log
在世修行1 天前
从零打造 C# 工业视觉检测系统(七):串口通信 SerialPort 封装与开发
开发语言·c#·modbus rtu·rs232/rs485
NoteStream1 天前
【C语言基础】分支和循环(上)
c语言·开发语言·c++·经验分享·笔记·算法·c#
lzhdim1 天前
C# 通过 Windows API 实现进程内存读写操作
开发语言·windows·c#
-银雾鸢尾-1 天前
C#中的预处理指令
开发语言·c#
dalong101 天前
Savitzky-Golay 的C# 实现
开发语言·kotlin·c#
猿长大人1 天前
C# | Autofac 新手指南:从零理解依赖注入与组件装配
c#·.net·di·依赖注入
show4331 天前
多格式导出怎么做?2026免费小程序TXT/SRT实践
开发语言·小程序·c#
czhaii1 天前
word插入表格排版创建或编辑应用技巧
ui·c#·xhtml