Aspose.Words LowCode Method to Remove BookMark and all it's range content

Hello Team !

Please can you add a LowCode method to remove a BookMark and all of it’s content, eg auto rebuilding the remainings before/after xml parts ?

Including each of these cases (non exhaustive) :

  • START/END in a header or footer
  • START/END in the same paragraph
  • STARD/END in differents sections
  • STARD/END IN the same cell
  • STARD/END in the same col (but not the same rows, and on the entire col or not)
  • STARD/END in the same row (but not the same cols, and on the entire row or not)
  • STARD/END in the same table, all the table or only on multiple entire rows or only on multiple entire cols or multiple neightboor’s cells (but not the entire row/col)
  • STARD/END in differents tables (not depending on the place for each ones : in table or in a row or in a col or in a cell)
  • START in a table, END outside a table (and reverse)
  • etc…

Many thanks !

@JYP

Could you please clarify what you mean by ‘LowCode method’? Are you looking for a specific implementation or a general approach?

A “all in one” like Word do → BookMark.Range.Clear() or BookMark.remove() or BookMark.Range.Text=“” I dont remember exactly the good syntax

working to clear all the content of the bookmark, undepending of its content and start/end location, rebuilding correctly the remaining’s parts

for example, for a bookmark starting in the middle of the first section, and ending in the middle of the 3nd section (so fully included the section 2) :

  • removing all the content betweend bk.start and bk.end so : end of section1 + the whole s2 + start of section3
  • rebuilding correctly the document “flow”, the start of the partial first section that remains, and just after, the end of the partial section 3 that remains

and, for the cherry on the cake ;-), please make it working well on DOTX/DOCX and DOT/DOC files format

Thank You

@JYP In general, to remove bookmark’s content you can simply set it’s text to empty string. So you can use code like the following to remove all bookmarks with their content from the document:

Document doc = new Document(@"C:\Temp\in.docx");

// Remove bookmakrs content.
doc.Range.Bookmarks.ToList()
    .ForEach(bk => bk.Text = "");
// Remove bookmakrs. 
doc.Range.Bookmarks.Clear();

doc.Save(@"C:\Temp\out.docx");

But in your list there are complex cases, like bookmarks in table. So there is no LowCode method to fulfill all of them and it will be required to work with Document Object Model to achieve what you need.