How to clone and add a table with bookmarks

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

Hi

Thanks for your inquiry. The problem occurs because document cannot contain few bookmarks with the same name. So duplicated bookmarks are removed. I think, the information provided in this thread could be useful for you:
https://forum.aspose.com/t/59821
Best regards,

Hi, Alex. Many thanks for the prompt reply. Your BookmarkVisitor class provided in the other thread sorts everything out. Spot on!

Thanks again.

Hi

It is perfect that you managed to resolve the problem. Please feel free to ask in case of any issues, I will be glad to help you.
Best regards,