I have developed a WinForms application which utilises the DocX Library for editing .docx files in memory.
I have one issue which i have searched Google vigorously, this is I would like to add a Table to my document using a specific index.
I do this by already having a blank table in the document and then finding the index and replacing the table with my table from my app using the index from the pre-existing table. I end up with this error:
Location: Part: /word/document.xml, Line: 22, Column: 0
I do not know if this is a DocX glitch or that I have approached this wrong.
The code below is not my app but some basic code which my app utilises.
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();
}
}
}