This project has moved. For the latest updates, please go here.

Insert Table Into Table

Nov 22, 2011 at 8:32 PM

I am looking to insert a 1 row, 3 column table into an existing 1 column table.

Is this possible? If so, is there an example?

Thanks,

Terry

Coordinator
Nov 22, 2011 at 10:00 PM
Hi tposhea,

here is an example of how to do what you want.

using (DocX document = DocX.Create("test.docx"))
{
// Insert a 1 column, 3 row Table.
Table t1 = document.AddTable(1, 3);
t1.Design = TableDesign.TableGrid;
document.InsertTable(t1);

// Get the first Paragraph out of the first cell out of the first row.
Paragraph p = document.Tables[0].Rows[0].Cells[0].Paragraphs[0];

// Insert the Table t2 before the Paragraph p.
Table t2 = document.AddTable(1, 3);
t2.Design = TableDesign.TableGrid;
p.InsertTableBeforeSelf(t2);

// Save the document to disk.
document.Save();
}

Kind regards,
Cathal