This topic describes the API operations that are related to Word document bookmarks.
Bookmarks
ActiveDocument.Bookmarks
Obtains all bookmarks in the active document.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarksexpression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; }
Methods
ActiveDocument.Bookmarks.Add()
Adds a bookmark.
Only JS-SDK V1.1.10 and later support this feature.
The feature applies only to PCs.
Syntax
expression.ActiveDocument.Bookmarks.Add({ Name, Range })expression: an Application object.
Parameters
Parameter
Type
Required
Description
Name
String
Yes
The name of the bookmark. The name must meet the following requirements:
The name can contain only letters.
The name cannot contain spaces, digits, and special characters, such as periods (.).
Range
Object
Yes
The range of text that is marked by the bookmark. A bookmark can be set to a collapsed range (the insertion point).
Description of Range
Parameter
Type
Required
Description
Start
Number
Yes
The starting position of the range marked by the bookmark.
End
Number
Yes
The ending position of the range marked by the bookmark.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); }
ActiveDocument.Bookmarks.GetBookmarkText()
Obtains the content in the bookmark.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.GetBookmarkText(Name)expression: an Application object.
Parameters
Parameter
Type
Required
Description
Name
String
Yes
The name of the bookmark.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Obtain the content of the bookmark. const bookmarkText = await bookmarks.GetBookmarkText('Aliyun'); console.log(bookmarkText); }
ActiveDocument.Bookmarks.Json()
Obtains information about all the bookmarks in the document.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Json()expression: an Application object.
Parameters
Parameter
Type
Description
name
String
The name of the bookmark.
begin
Number
The starting position of the bookmark.
end
Number
The end position of the bookmark.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await app.ActiveDocument.Bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Obtain information about all the bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks.Json(); console.log(bookmarks); }
ActiveDocument.Bookmarks.ReplaceBookmark()
Replaces the content of the specified bookmark.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.ReplaceBookmark(Data)expression: an Application object.
Parameters
Parameter
Type
Required
Description
Data
Array.<Object>
Yes
The struct of the content with which you want to replace.
Description of Data
Parameter
Type
Required
Description
name
String
Yes
The name of the bookmark whose content you want to replace.
type
String
Yes
The type of the bookmark whose content you want to replace. Set this parameter to TEXT.
value
String
Yes
The content with which you want to replace.
Return value
A value of type
Boolean. If the return value istrue, the replacement was successful. If the return value isfalse, the replacement failed.Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Replace the content of the bookmark. const isReplaceSuccess = await bookmarks.ReplaceBookmark([ { name: 'Aliyun', type: 'text', value: 'Content to replace with', }, ]); console.log(isReplaceSuccess); }ActiveDocument.Bookmarks.Exists(Name)
Checks whether the specified bookmark exists.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Exists(Name)expression: an Application object.
Parameters
Parameter
Type
Required
Description
Name
String
Yes
The name of the bookmark.
Return value
A value of type
Boolean. If the return value istrue, the bookmark exists. Otherwise, the bookmark does not exist.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 whether the bookmark exists. const isExist = await app.ActiveDocument.Bookmarks.Exists('WebOffice'); console.log(isExist); // true }Properties
ActiveDocument.Bookmarks.Count
Returns the number of Bookmark content controls in the active document.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Countexpression: an 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, }, }); // Obtain the number of bookmarks. const count = await app.ActiveDocument.Bookmarks.Count; console.log(count); }ActiveDocument.Bookmarks.DefaultSorting
Sets the sorting option for bookmarks.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.DefaultSorting = WdBookmarkSortByexpression: an Application object.
For more information about
WdBookmarkSortBysettings, see Enum.WdBookmarkSortBy.async function example() { await instance.ready(); const app = instance.Application; //Sort the bookmarks. const sort = await app.ActiveDocument.Bookmarks.DefaultSorting; // Set the bookmark sorting option. app.ActiveDocument.Bookmarks.DefaultSorting = 0; }For more information about WdBookmarkSortBy, see Enum.WdBookmarkSortBy
Bookmark
ActiveDocument.Bookmarks.Item()
Obtains the specified bookmark.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name)expression: an Application object.
Parameters
Parameter
Type
Required
Description
Name
String
Yes
The name of the bookmark.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Obtain the bookmark. await app.ActiveDocument.Bookmarks.Item('Aliyun'); }
Methods
ActiveDocument.Bookmarks.Item(Name).Delete()
Deletes the specified bookmark.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Delete()expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Obtain the bookmark. await app.ActiveDocument.Bookmarks.Item('Aliyun'); // Delete the bookmark. await app.ActiveDocument.Bookmarks.Item('Aliyun').Delete(); }ActiveDocument.Bookmarks.Item(Name1).Copy(Name2)
Copies the specified bookmark.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name1).Copy(Name2)expression: an Application object.
Parameters
Parameter
Type
Required
Description
Name
String
Yes
The name of the bookmark.
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()
Selects the specified bookmark.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Select()expression: an 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 content marked by the bookmark. await app.ActiveDocument.Bookmarks.Item('WebOffice').Select(); }
Properties
ActiveDocument.Bookmarks.Item(Name).Name
Obtains the name of the specified bookmark.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Nameexpression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain all bookmarks in the active document. const bookmarks = await app.ActiveDocument.Bookmarks; // Add a bookmark. await bookmarks.Add({ Name: 'Aliyun', Range: { Start: 1, End: 10, }, }); // Obtain the bookmark. await app.ActiveDocument.Bookmarks.Item('Aliyun'); // Obtain the name of the bookmark. await app.ActiveDocument.Bookmarks.Item('Aliyun').Name; }ActiveDocument.Bookmarks.Item(Name).Empty
Determines whether the specified bookmark is empty.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Emptyexpression: an 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 whether the bookmark is empty. const isEmpty = await app.ActiveDocument.Bookmarks.Item('WebOffice').Empty; console.log(isEmpty); // false }ActiveDocument.Bookmarks.Item(Name).Start
Obtains the starting position of the content in the specified bookmark.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Startexpression: an 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, }, }); // Obtain the starting position of the content in the bookmark. const start = await app.ActiveDocument.Bookmarks.Item('WebOffice').Start; console.log(start); // 1 }ActiveDocument.Bookmarks.Item(Name).End
Obtains the ending position of the content in the specified bookmark.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Endexpression: an 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, }, }); // Obtain the ending position of the content in the specified bookmark. const end = await app.ActiveDocument.Bookmarks.Item('WebOffice').End; console.log(end); // 10 }ActiveDocument.Bookmarks.Item(Name).Range
Obtains the range of the document that is contained in the specified bookmark.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Rangeexpression: an 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, }, }); // Obtain the document range that is contained in the bookmark. await app.ActiveDocument.Bookmarks.Item('WebOffice').Range; }ActiveDocument.Bookmarks.Item(Name).StoryType
Obtains the story type of the specified bookmark.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).StoryTypeexpression: an 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, }, }); // Obtain the story type of the bookmark. await app.ActiveDocument.Bookmarks.Item('WebOffice').StoryType; }ActiveDocument.Bookmarks.Item(Name).Column
Determines whether the specified bookmark is a table column.
ImportantOnly JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.Bookmarks.Item(Name).Columnexpression: an 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, }, }); // Determine whether the bookmark is a table column. const column = await app.ActiveDocument.Bookmarks.Item('WebOffice').Column; console.log(column); // false }