Clone a table

Apr 23, 2014 at 2:52 PM
Is there a way to (deep)clone a Table?

For example; I have a table in my DocX document which need to be cloned and values need to be changed after each clone.

When I do something like (pseude code):
Table tTemplate = [find the template Table];
Table tCopy = docx.InsertTable(tTemplate);
and then change text in cells/paragraphs of tCopy (for instance using a replacetext) then all the table values of all table copies are the same.

I think I need something like a deepclone function for tables? Does something exist like this in DocX?

Thanks in advance.
Apr 23, 2014 at 10:21 PM
Thread can be closed; found another way to solve my problem; just copying the table and editing contents by traversing the table copies.
Marked as answer by lckuiper on 4/23/2014 at 3:22 PM
Developer
Apr 28, 2014 at 9:06 PM
Maybe you could create a method that would do the cloning using the solution you used. I guess this could be good addition and useful for some people.
May 6, 2014 at 8:54 AM
Edited May 6, 2014 at 9:15 AM
can you post the solution / Clone method?

UPDATE

my solution if someone needs it (pseudo code):
var sourceTable = document.Tables[index_in_template]; // get the table from template you want to duplicate

for (int i = 0; i <= how_many_count - 1; i++)
{
      document.InsertTable(sourceTable); // inserting the required number of source tables
}

var stream = new MemoryStream();
document.SaveAs(stream); // this is it - you have to save it as it is now (with tables duplicated)

document = DocX.Load(stream); // reload with duplicated 

... [HERE YOU CAN ITERATE AND FILL THE TABLES NOW] ...