Hey, I use Aspose Words in my NET Core project, so I have to do interesting task:
I have a first Word document, what have bookmark with name “Bills”. I need to copy a content of this bookmark to bookmark of second Word document, bookmark’s name is “Bills” too.
Yeap, I can use Text attribute of Bookmark class, but it moves only text, not text with tables, formatting, ext.
What is the best way to do it with formatting?
@Todorowski you may find the following information helpful.
Thank you very much.
I tried this solution, but I got some Exception:
System.ArgumentException: Cannot insert a node of this type at this location.
var content = ExtractContentHelper.ExtractContent(item.BookmarkStart, item.docBookmark, false);
content.Reverse();
var parent = newBookmark.BookmarkStart.ParentNode;
foreach (var node in content)
{
var newNode = importer.ImportNode(node, true);
parent.InsertAfter(newNode, null);
}
@Todorowski Please, attach the source document here we will check the issue and provide you more information.
I finally found good solution (sorry, I forgot to use NodeImporter functionality).
So, my summary solution (maybe, it will be helpful for someone):
var content = ExtractContentHelper.ExtractContent(oldBookmark.BookmarkStart,
oldBookmark.BookmarkEnd, false);
if (!content.Any())
{
continue;
}
newBookmark.Text = string.Empty;
var destination = (Node)newBookmark.BookmarkStart.ParentNode;
var parent = destination.ParentNode;
foreach (var node in content)
{
var newNode = importer.ImportNode(node, true);
parent.InsertAfter(newNode, destination);
destination = newNode;
}
Vadim thank you for lighting the right way.
@Todorowski, please feel free to ask in case of any issues, we will be glad to help you.