Hi,
we are trying to replace the text of a bookmark in a Word document using Aspose.Words.DLL for .NET version 19.10. Instead of replacing the whole bookmark text, the replacement text appears next to the existing bookmark text.
The code is as follows:
var wordDoc = new Aspose.Words.Document(@"before.docx");
var bookmark = wordDoc.Range.Bookmarks[1];
bookmark.Text = "edited bookmark text";
var saveFormat = Aspose.Words.SaveFormat.Docx;
var outStream = new MemoryStream();
wordDoc.Save(outStream, saveFormat);
File.WriteAllBytes(@"after.docx", outStream.ToArray());
Please find attached files before.docx and after.docx in the attached ZIP file to demonstrate this behaviour. bookmark-text.zip (31.1 KB)
The expected result would be that the whole bookmark text wold be replaced with our custom text. Unfortunately, we can’t remove the bookmark after filling it to get rid of the previous text, because it may need to be filled with a different value later on. Please take a look at this behaviour and let us know if and when it can be fixed.