javascriptoffice-jsadd-inword-addins

I want to get All hidden Bookmarks from word document using office JS


I want to Get All hidden bookmarks names from my document in word using word JS add-in using this is I am trying but not done.

getBookmarks(includeHidden, includeAdjacent)

 await Word.run(async (context) => {
    const bookmarks = context.document.getBookmarks(true); // Set includeHidden to true
    context.load(bookmarks, 'items');

    await context.sync();

     // Iterate through the bookmarks and log their names
      for (let i = 0; i < bookmarks.items.length; i++) {
           const bookmark = bookmarks.items[i];
            console.log('Bookmark Name:', bookmark);
           }
      });


Solution

  • using this I got all hidden bookmarks

          await Word.run(async (context) => {
          const body = context.document.body.getRange();
          let bookmarks = body.getBookmarks(true, true);
    
          await context.sync();
          console.log(bookmarks.value);
      });