Posted 28 March 2024, 12:23 pm EST
I need to insert text in the bookmark in a word document, im using below c# code, but t.Texts is coming as empty array always, so im getting index out of range error.
var doc = new GcWordDocument(); doc.Load(@"H:\aspose_templates\template.dotx"); var bmks = doc.Body.Bookmarks; setBmkText("name", "Mr."); void setBmkText(string bmk, string value) { if (!bmks.Contains(bmk)) return; var t = bmks[bmk].GetRange(); t.Texts[0].Value = value; for (int i = t.Texts.Count - 1; i > 0; --i) t.Texts[i].Delete(); } doc.Save(@"H:\aspose_templates\new\template.docx");