c# - How can I remove bookmarks from an OpenXML docx file? -
i thought following work:
var bod = worddoc.maindocumentpart.document.body; foreach (var bookmark in bod.descendants<bookmarkstart>()) { bookmark.remove(); } foreach (var bookmark in bod.descendants<bookmarkend>()) { bookmark.remove(); }
but corrupts file.
try this, worked on document.
var bs = worddoc.maindocumentpart.document .descendants<bookmarkstart>() .tolist(); foreach (var s in bs) s.remove(); var = worddoc.maindocumentpart.document .descendants<bookmarkend>() .tolist(); foreach (var e in be) e.remove();
Comments
Post a Comment