Hi, what we have defined in the template is a table with bookmarks defined for cells. What we want to do is dynamically generate multi-instance of the tables and append it after the original table. The code we have tried are:
public void DuplicateTable(string tableBookmark)
{
Table sourceTable = GetAncesterTableForBookmark(tableBookmark);
if (sourceTable != null)
{
Node duplicateTable = sourceTable.Clone(true);
Paragraph paragraph = new Paragraph(_document);
sourceTable.ParentNode.InsertAfter(paragraph, sourceTable);
sourceTable.ParentNode.InsertAfter(duplicateTable, sourceTable);
}
}
public Table GetAncesterTableForBookmark(string bookmarkName)
{
bool bookmarkExist = _docBuilder.MoveToBookmark(bookmarkName);
if (bookmarkExist)
{
Node table = _docBuilder.CurrentParagraph.GetAncestor(NodeType.Table);
if (table != null)
{
return table as Table;
}
}
return null;
}
It can generate new table and insert after the original one as required. However, the newly generated table does not have got any bookmark thus when manipulating it we don’t know where to write the content. Is there any way of cloning a table and generating the bookmark smartly (e.g., original table cell bookmark ‘image’, cloned table with cell bookmark ‘image1’, ‘image2’).
Thought about creating new Section and append it at the end but do not know whether that will result in page break between each newly generated Section.
Many thanks in advance