This project has moved and is read-only. For the latest updates, please go here.

Error when trying to copy and insert a table

May 4, 2015 at 2:03 PM
I'm trying to create/manipulate Word .docx files using the DocX nuget package.

The documentation has the following example:
// Place holder for a Table.
Table t;

// Load document a.
using (DocX documentA = DocX.Load(@"C:\Example\a.docx"))
{
    // Get the first Table from this document.
    t = documentA.Tables[0];
}

// Load document b.
using (DocX documentB = DocX.Load(@"C:\Example\b.docx"))
{
    /* 
     * Insert the Table that was extracted from document a, into document b. 
     * This creates a new Table that is now associated with document b.
     */
    Table newTable = documentB.InsertTable(t);

    // Save all changes made to document b.
    documentB.Save();
}// Release this document from memory.
When the code executes I receive an error when inserting the table: Table newTable = documentB.InsertTable(t);
Error: System.InvalidOperationException {"Sequence contains no elements"}

I am at a loss as to why this is occurring. I have looked at the table "t" that is being inserted and it appears to have all of the properties populated. I am unclear as to what is causing the error.

Any help would be greatly appreciated.
May 4, 2015 at 2:14 PM
Stop using niget package. Its outdated. Use sources or binary from here.
May 4, 2015 at 3:24 PM
Thanks for the quick reply MadBoy.

I have switched over to using the lastest version of the DLL downloaded from this site.

I was still having this problem. However I compared the table that I was coping from my source document to a table that I created directly using the DocX.dll.

I found that for some reason the Design property on my source table was not set to anything, however table that I created directly was set to Novacode.TableDesign.TableGrid.

I am now set this property after reading the table for my source and everything works as expected.
mytable.Design = Novacode.TableDesign.TableGrid;