We are trying to insert a bookmark that contains a sub-range from a table, like in the attached WordCreatedBookmark.png.
Using the following code:
using(var ms = new MemoryStream(File.ReadAllBytes(@"C:\1.docx")))
{
var doc = new Document(ms);
var bookmarkStart = new BookmarkStart(doc, "bookmark");
var bookmarkEnd = new BookmarkEnd(doc, "bookmark");
var table = (Table) doc.GetChildNodes(NodeType.Table, true)[0];
table.Rows[1].Cells[1].Paragraphs[0].ChildNodes.Insert(0, bookmarkStart);
table.Rows[5].Cells[3].Paragraphs[table.Rows[5].Cells[3].Paragraphs.Count - 1].ChildNodes.Add(bookmarkEnd);
doc.Save(@"C:\Users\IBM_ADMIN\Desktop\11.docx", SaveFormat.Docx);
}
We are getting the result from AsposeCreatedBookmark.png. As you can observe from the attached images inserting a bookmark with Aspose is not having the desired effect.
After investigating the Microsoft Word behavior we concluded that it is using the “colFirst” and “colLast” attributes on the bookmarkStart XML element, like:
<w:bookmarkStart w:id="0" w:name="bookmark" w:colFirst="1" w:colLast="3"/>
Please let us know if there is a way to atchive the described behavior.
Thank you,
Lucian Nistor