We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Clone Table with Range.Bookmarks

We use Aspose version .Net.

So far used version .Net.

Currently we have the problem that the cloning of tables does not have the clone all sub Ranges and Bookmarks with (see figure).

The following error message appears:
'(Aspose.Words.Bookmark) ((new System.Linq.SystemCore_EnumerableDebugView (((Aspose.Words.Tables.Table) tableCloneNode) .Range.Bookmarks)) Type 'System.InvalidOperationException'

string docPath = Path.Combine(Directory.GetCurrentDirectory(), @"testdoc\CloneDokument.docx");

Document doc = new Document(docPath);

Node table = doc.GetChild(NodeType.Table, 0, true);
Node tableCloneNode = table.Clone(true);

Used Document: See Attachment
Hi Denoshan,

Thanks for your inquiry.

Please note that Aspose.Words mimics the same behavior as MS Word does. MS Word allows only unique names for bookmarks. If you change the name of a bookmark to a name that already exists in the document, no error will be given and only the first bookmark will be stored when you save the document.

If you append the cloned table at the end of document, the bookmark is not saved in output document.

Hi Tahir

If we cloning the table with the Aspose version does not show any error.

We do not want to process the table further, but we need cloning for an evaluation and process with the rows.

Can you tell us why the cloning from the table in version no longer works as in version

Hi Denoshan,

Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. The BookmarkEnd node of bookmark "OI_TABLE_SUB" is outside the table. So, this bookmark is not properly cloned. Please check the attached DOM image for detail.

Please use following workaround to fix this issue. Hope this helps you.

Document doc = new Document(MyDir + "CloneDokument.docx");


Node table = doc.GetChild(NodeType.Table, 0, true);

Table tableCloneNode = (Table)table.Clone(true);

tableCloneNode.LastRow.LastCell.LastParagraph.AppendChild(new BookmarkEnd(doc, "OI_TABLE_SUB"));

Hi Tahir

Thank you for your answer.

I wonder why the cloning with this document in and with the version works and from there no more.

Cloning works as long as we don't have bookmarks within a bookmark inside.

What we do (example):
1: We determine the table (Table table = (Table)doc.GetChild(NodeType.Table, 0, true);)
2: Determine the bookmarks within a table
3: Cloning the bookmarks within the table ("x" times)
4: Fill the clones with data and paste into the table (table.Ranges.Bookmarks[0].Text)
5: Save the table

We have the problem that from version the inner read-write always has an error on the list with the bookmarks (Ranges -> Bookmakrs -> Bookmark -> Text "System.InvalidOperationException"

We can no longer perform step 4 because we can no longer replace the text.

See picture above ...

Your input with the "DocumentExplorer" and bookmark outside is super.
But as already mentioned, this approach works with the same code and document up to and with version

'We tried using NuGet various versions with "try and error" until I could determine up to which version our approach works.

Thanks for your help.
I hope we find a solution and hope our problem has been understood.

Best regards
Hi Denoshan,

Thanks for your inquiry. We have logged this problem in our issue tracking system as WORDSNET-15347. You will be notified via this forum thread once this issue is resolved. Please use the workaround shared in my previous post.

We apologize for your inconvenience.

Hi Tahir

We have found the difference between the versions.
Previously the bookmarks that were not inside a table were also not recognized/found.
However, if the bookmark was outside a table was passed an exception (was “null”). An now is thrown exception when the bookmark (BookmarkEnd) is outside the table.

Thank you for your help.

Best regrads
Hi Denoshan,

Thanks for sharing the detail. The BookmarkEnd node is inside next sibling (Paragraph) of Table node. See the attached image for detail. We will inform you via this forum thread once this issue is resolved.

We apologize for your inconvenience.