我开发了一个 WinForms 应用程序,它利用 DocX 库来编辑内存中的 .docx 文件。
我有一个问题,我已经在 Google 上大力搜索,这是我想使用特定索引向我的文档中添加一个表格。
为此,我已经在文档中有一个空白表,然后使用预先存在的表中的索引找到索引并用我的应用程序中的表替换该表。我最终得到这个错误:
位置:部分:/word/document.xml,行:22,列:0
我不知道这是 DocX 故障还是我处理错了。
下面的代码不是我的应用程序,而是我的应用程序使用的一些基本代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Novacode;
namespace DocXTesting
{
class Program
{
static void Main(string[] args)
{
using (DocX document = DocX.Load(@"Test.docx"))
{
Table t = document.Tables[0];
int tIndex = t.Index;
try
{
t.Remove();
Table newTable = document.InsertTable(tIndex, 4, 4);
document.Save();
}
catch (Exception x)
{
Console.WriteLine(x.Message);
}
}
Console.ReadKey();
}
}
}