Bookmark class

Bookmark class

Represents a single bookmark. To learn more, visit the Working with Bookmarks documentation article.

Remarks

Bookmark is a “facade” object that encapsulates two nodes Bookmark.bookmarkStart and Bookmark.bookmarkEnd in a document tree and allows to work with a bookmark as a single object.

Properties

NameDescription
bookmarkEndGets the node that represents the end of the bookmark.
bookmarkStartGets the node that represents the start of the bookmark.
firstColumnGets the zero-based index of the first column of the table column range associated with the bookmark.
isColumnReturns true if this bookmark is a table column bookmark.
lastColumnGets the zero-based index of the last column of the table column range associated with the bookmark.
nameGets or sets the name of the bookmark.
textGets or sets the text enclosed in the bookmark.

Methods

NameDescription
remove()Removes the bookmark from the document. Does not remove text inside the bookmark.

Examples

Shows how to add bookmarks and update their contents.

test('CreateUpdateAndPrintBookmarks', () => {
  // Create a document with three bookmarks, then use a custom document visitor implementation to print their contents.
  let doc = CreateDocumentWithBookmarks(3);
  let bookmarks = doc.range.bookmarks;
  expect(bookmarks.count).toEqual(3);

  // Bookmarks can be accessed in the bookmark collection by index or name, and their names can be updated.
  bookmarks.at(0).name = `${bookmarks.at(0).name}_NewName`;
  bookmarks.at("MyBookmark_2").text = `Updated text contents of ${bookmarks.at(1).name}`;
});

See Also