Bookmark

更新时间:
复制 MD 格式

This topic describes the APIs for bookmarks in Word documents.

Bookmarks

ActiveDocument.Bookmarks

Retrieves all bookmarks in the document.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks

    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;
    }

Methods

ActiveDocument.Bookmarks.Add()

Use the Add() method to add a bookmark.

Important
  • 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.

Important

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.

Important

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.

Important

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. true indicates that the replacement succeeded. false indicates 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.

    Important

    This 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. true indicates that the bookmark exists. false indicates 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 Count property to retrieve the number of document content controls.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Count

    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,
        },
      });
    
      // Get the number of bookmarks.
      const count = await app.ActiveDocument.Bookmarks.Count;
      console.log(count);
    }

    ActiveDocument.Bookmarks.DefaultSorting

    Use the DefaultSorting property to set the bookmark sorting order.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.DefaultSorting = WdBookmarkSortBy

    expression: 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.

Important

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.

Important

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.

    Important

    This 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.

    Important

    This 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.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Item(Name).Name

    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');
    
      // Get the name of the single bookmark.
      await app.ActiveDocument.Bookmarks.Item('Aliyun').Name;
    }

    ActiveDocument.Bookmarks.Item(Name).Empty

    Use the Empty property to check if the bookmark content is empty.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Item(Name).Empty

    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,
        },
      });
    
      // 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 Start property to retrieve the start position of the bookmark content.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Item(Name).Start

    Expression: 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 End property to retrieve the end position of the bookmark content.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Item(Name).End

    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,
        },
      });
    
      // 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 Range property to retrieve the content area of the bookmark.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Item(Name).Range

    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,
        },
      });
    
      // Get the content area of the bookmark.
      await app.ActiveDocument.Bookmarks.Item('WebOffice').Range;
    }

    ActiveDocument.Bookmarks.Item(Name).StoryType

  • Use the StoryType property to retrieve the type of the bookmark content.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Item(Name).StoryType

    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,
        },
      });
    
      // Get the type of the bookmark content.
      await app.ActiveDocument.Bookmarks.Item('WebOffice').StoryType;
    }

    ActiveDocument.Bookmarks.Item(Name).Column

  • Use the Column property to check if the bookmark content is a table column.

    Important

    This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Bookmarks.Item(Name).Column

    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,
        },
      });
    
      // Check if the bookmark content is a table column.
      const column = await app.ActiveDocument.Bookmarks.Item('WebOffice').Column;
      console.log(column); // false
    }