This topic describes the APIs for bookmarks in Word documents.
Bookmarks
ActiveDocument.Bookmarks
Retrieves all bookmarks in the document.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarksexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; }
Methods
ActiveDocument.Bookmarks.Add()
Use the Add() method to add a bookmark.
This feature is supported in JS-SDK V1.1.10 and later.
This feature is available only on PCs.
Syntax
expression.ActiveDocument.Bookmarks.Add({ Name, Range })expression: A document application object.
Parameters
Property
Data Type
Required
Description
Name
String
Yes
The bookmark name. The naming conventions are as follows:
Must be a single word.
Cannot contain spaces, numbers, or special characters such as periods (.).
Range
Object
Yes
The text area to mark with the bookmark. You can set a bookmark to a collapsed area (an insertion point).
Range details
Property
Data Type
Required
Description
Start
Number
Yes
The start point of the bookmark.
End
Number
Yes
The end point of the bookmark.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); }
ActiveDocument.Bookmarks.GetBookmarkText()
Use the GetBookmarkText() method to retrieve the content of a bookmark.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.GetBookmarkText(Name)expression: A document application object.
Parameters
Property
Data Type
Required
Description
Name
String
Yes
The bookmark name.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Get the bookmark content. const bookmarkText = await bookmarks.GetBookmarkText('Aliyun'); console.log(bookmarkText); }
ActiveDocument.Bookmarks.Json()
Use the Json() method to retrieve information about all bookmarks.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Json()expression: A document application object.
Parameters
Property
Data Type
Description
name
String
The bookmark name.
begin
Number
The start position of the bookmark.
end
Number
The end position of the bookmark.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Get information about all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks.Json(); console.log(bookmarks); }
ActiveDocument.Bookmarks.ReplaceBookmark()
Use the ReplaceBookmark() method to replace the content of a bookmark.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.ReplaceBookmark(Data)expression: A document application object.
Parameters
Property
Data Type
Required
Description
Data
Array.<Object>
Yes
The struct for the replacement content.
Data description
Property
Data Type
Required
Description
name
String
Yes
You can replace the bookmark name.
type
String
Yes
The type of the bookmark to replace. The bookmark type is TEXT.
value
String
Yes
The new content for the bookmark.
Return value
Returns
Boolean.trueindicates that the replacement succeeded.falseindicates that it failed.Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Replace the bookmark content. const isReplaceSuccess = await bookmarks.ReplaceBookmark([ { name: 'Aliyun', type: 'text', value: 'New bookmark content', }, ]); console.log(isReplaceSuccess); }ActiveDocument.Bookmarks.Exists(Name)
Use the
Exists(Name)method to check if a bookmark exists.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Exists(Name)expression: A document application object.
Parameters
Parameter
Data Type
Required
Description
Name
String
Yes
The bookmark name.
Return value
Returns Boolean.
trueindicates that the bookmark exists.falseindicates that it does not.Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Check if the bookmark exists. const isExist = await app.ActiveDocument.Bookmarks.Exists('WebOffice'); console.log(isExist); // true }Properties
ActiveDocument.Bookmarks.Count
You can use the
Countproperty to retrieve the number of document content controls.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Countexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Get the number of bookmarks. const count = await app.ActiveDocument.Bookmarks.Count; console.log(count); }ActiveDocument.Bookmarks.DefaultSorting
Use the
DefaultSortingproperty to set the bookmark sorting order.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.DefaultSorting = WdBookmarkSortByexpression: A document application object.
For more information about
WdBookmarkSortBy, see Enum.WdBookmarkSortBy.async function example() { await instance.ready(); const app = instance.Application; // Bookmark sorting. const sort = await app.ActiveDocument.Bookmarks.DefaultSorting; // Set the bookmark sorting order. app.ActiveDocument.Bookmarks.DefaultSorting = 0; }
Bookmark
ActiveDocument.Bookmarks.Item()
Retrieves a single bookmark object.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name)expression: A document application object.
Parameters
Property
Data Type
Required
Description
Name
String
Yes
The bookmark name.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Get a single bookmark object. await app.ActiveDocument.Bookmarks.Item('Aliyun'); }
Methods
ActiveDocument.Bookmarks.Item(Name).Delete()
Use the Delete() method to delete a single bookmark.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Delete()expression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Get a single bookmark object. await app.ActiveDocument.Bookmarks.Item('Aliyun'); // Delete the single bookmark. await app.ActiveDocument.Bookmarks.Item('Aliyun').Delete(); }ActiveDocument.Bookmarks.Item(Name1).Copy(Name2)
Use the
Copy()method to copy a single bookmark.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name1).Copy(Name2)expression: A document application object.
Parameters
Property
Data Type
Required
Description
Name
String
Yes
The bookmark name.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Copy the bookmark. await app.ActiveDocument.Bookmarks.Item('WebOffice').Copy('NewBookmark'); }ActiveDocument.Bookmarks.Item(Name).Select()
Use the
Select()method to select the bookmark.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Select()expression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Select the bookmark content. await app.ActiveDocument.Bookmarks.Item('WebOffice').Select(); }
Properties
ActiveDocument.Bookmarks.Item(Name).Name
Use the Name property to retrieve the name of a single bookmark.
This feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Nameexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all bookmarks. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Get a single bookmark object. await app.ActiveDocument.Bookmarks.Item('Aliyun'); // Get the name of the single bookmark. await app.ActiveDocument.Bookmarks.Item('Aliyun').Name; }ActiveDocument.Bookmarks.Item(Name).Empty
Use the
Emptyproperty to check if the bookmark content is empty.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Emptyexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Check if the bookmark content is empty. const isEmpty = await app.ActiveDocument.Bookmarks.Item('WebOffice').Empty; console.log(isEmpty); // false }ActiveDocument.Bookmarks.Item(Name).Start
Use the
Startproperty to retrieve the start position of the bookmark content.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).StartExpression: Document-Type Application Object
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Start position of the bookmark content. const start = await app.ActiveDocument.Bookmarks.Item('WebOffice').Start; console.log(start); // 1 }ActiveDocument.Bookmarks.Item(Name).End
Use the
Endproperty to retrieve the end position of the bookmark content.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Endexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // End position of the bookmark content. const end = await app.ActiveDocument.Bookmarks.Item('WebOffice').End; console.log(end); // 10 }ActiveDocument.Bookmarks.Item(Name).Range
Use the
Rangeproperty to retrieve the content area of the bookmark.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Rangeexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Get the content area of the bookmark. await app.ActiveDocument.Bookmarks.Item('WebOffice').Range; }ActiveDocument.Bookmarks.Item(Name).StoryType
Use the
StoryTypeproperty to retrieve the type of the bookmark content.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).StoryTypeexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Get the type of the bookmark content. await app.ActiveDocument.Bookmarks.Item('WebOffice').StoryType; }ActiveDocument.Bookmarks.Item(Name).Column
Use the
Columnproperty to check if the bookmark content is a table column.ImportantThis feature is supported in JS-SDK V1.1.10 and later.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Columnexpression: A document application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'WebOffice', Range: { Start: 1, End: 10, }, }); // Check if the bookmark content is a table column. const column = await app.ActiveDocument.Bookmarks.Item('WebOffice').Column; console.log(column); // false }