Document

Updated at:

This topic describes the APIs for the Document object, which is used for text documents.

Document

ActiveDocument

Returns the active document.

Syntax: expression.ActiveDocument, where expression is a variable that represents a document-type application object.

Method

ActiveDocument.BuiltinDocumentProperties()

Use the BuiltinDocumentProperties() method to get all the built-in properties of a document.

  • Syntax: expression.ActiveDocument.BuiltinDocumentProperties({Name})

    expression: A document type application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Name

    string

    Yes

    The name of the built-in property. Possible values include:

    • Title: Document title.

    • Security: Security value.

    • Size: Document size.

    • Author: Document author.

    • CorpId: Corporation ID.

    • Guid: Secure document ID.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the Title property
      const title = await app.ActiveDocument.BuiltinDocumentProperties('Title');
      console.log(title);
    }

ActiveDocument.ExportAsFixedFormat()

The ExportAsFixedFormat() method exports the current text document as a PDF or IMG file and returns the URL of the exported file.

  • Syntax

    expression.ActiveDocument.ExportAsFixedFormat({ OutputFileName, ExportFormat })

    expression: A variable that represents the application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    OutputFileName

    String

    No

    The path and file name for the exported file. Not supported in the current version.

    ExportFormat

    Enum

    No

    The format of the exported file. Currently, only the image and PDF formats are supported. For more information, see WdExportFormat.

    OpenAfterExport

    Boolean

    No

    Whether to open the new file after exporting. Not supported in the current version.

    OptimizeFor

    Enum

    No

    Whether to optimize for screen display or printing. Not supported in the current version. For more information, see WdExportOptimizeFor.

    Range

    Enum

    No

    The page range to export. For more information, see WdExportRange.

    From

    Number

    No

    The start page number when the Range parameter is set to wdExportFromTo.

    To

    Number

    No

    The end page number when the Range parameter is set to wdExportFromTo.

    Item

    Enum

    No

    Whether to export only text or text with markup. For more information, see WdExportItem.

    IncludeDocProps

    Boolean

    No

    Whether to include the source document's properties in the exported file. The possible values are:

    • true (default): Yes.

    • false: No.

    KeepIRM

    Boolean

    No

    Whether to copy IRM permissions to the exported XPS document if the source document has IRM protection. Not supported in the current version. The possible values are:

    • true (default): Yes.

    • false: No.

    CreateBookmarks

    Enum

    No

    Whether to export bookmarks and, if so, which type to export. Not supported in the current version. For more information, see WdExportCreateBookmarks.

    DocStructureTags

    Boolean

    No

    Whether to include document structure tags to improve accessibility for screen readers, for example, information about the flow and logical organization of the content. The possible values are:

    • true (default): Yes.

    • false: No.

    BitmapMissingFonts

    Boolean

    No

    Whether to render text as a bitmap instead of embedding the font. Not supported in the current version. The possible values are:

    • true (default): Renders text as a bitmap. This avoids font embedding and substitution issues.

    • false: References the font in the file. A viewing application will substitute a different font if the original is unavailable.

    UseISO19005_1

    Boolean

    No

    Whether to limit the exported file to the PDF/A (ISO 19005-1) subset. Not supported in the current version. The possible values are:

    • false (default): No.

    • true: Yes. The resulting file is more reliably self-contained but may be larger or show more visual artifacts due to the format restrictions.

    FixedFormatExtClassPtr

    Enum

    No

    A pointer to an add-in for an alternate export implementation. The add-in interprets the application's EMF and EMF+ page descriptions to generate its own PDF or XPS file. Not supported in the current version.

    DPI

    Number

    No

    The DPI of the exported image. The default value is 92.

    Combine2LongPic

    Boolean

    No

    Whether to combine all pages into a single long image. The possible values are:

    • false (default): No.

    • true: Yes.

    ImgFormat

    Enum

    No

    The format of the exported image. For more information, see WdExportImgFormat.

    WaterMark

    Boolean

    No

    Whether to include a watermark. The possible values are:

    • false (default): No.

    • true: Yes.

  • Return value

    The URL of the exported file.

  • Example

    • Export as a PDF

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
      
        // Export as a PDF and get the exported URL
        const pdfUrl = await app.ActiveDocument.ExportAsFixedFormat(); // The export format defaults to PDF.
        console.log(pdfUrl);
      }
    • Export as an image

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
      
        // Export as an image and get the exported URL
        const imgUrl = await app.ActiveDocument.ExportAsFixedFormat({ ExportFormat: app.Enum.WdExportFormat.wdExportFormatIMG }); // The integer value for this enum is 19.
        console.log(imgUrl);
      }

ActiveDocument.GetAtList()

The GetAtList() method retrieves a list of mentioned users from the text.

  • Syntax

    expression.ActiveDocument.GetAtList()

    expression: A document type application object.

  • Return value

    Returns the mention list as an array of objects, each containing the uuid field.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the mention list from the text.
      const atInfo = await app.ActiveDocument.GetAtList();
      console.log(atInfo);
    }

ActiveDocument.GetAtPos()

Use the GetAtPos() method to get the Range object for an at-sign mention by its UUID.

  • Syntax

    expression.ActiveDocument.GetAtPos({ Uuid })

    expression: A variable representing a document type application object.

  • Parameters

    This method accepts an object with the following property as its parameter.

    Parameter

    Type

    Required

    Description

    Uuid

    string

    Yes

    The UUID of the @-mention.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the Range object of an @-mention by its UUID.
      const range = await app.ActiveDocument.GetAtPos({ Uuid: "" });
      console.log(range);
    }

ActiveDocument.GetContainerAttributes()

Use GetContainerAttributes() to get the size of the text container.

Important

This feature requires JS-SDK version 1.1.10 or later.

  • Syntax

    expression.ActiveDocument.GetContainerAttributes()

    Expression: The application object.

  • Return value

    Parameter

    Type

    Description

    Width

    Number

    The width of the text container.

    Height

    Number

    The height of the text container.

    OffsetLeft

    Number

    The distance in pixels from the element's outer left border to the inner left border of its offsetParent.

    OffsetTop

    Number

    The distance in pixels from the element's outer top border to the inner top border of its offsetParent.

    ClientWidth

    Number

    The inner width of the element.

    ClientHeight

    Number

    The inner height of the element.

    OffsetWidth

    Number

    The layout width of the element.

    OffsetHeight

    Number

    The layout height of the element.

    ScrollTop

    Number

    The vertical scroll offset of the element's content, in pixels.

    ScrollLeft

    Number

    The horizontal scroll offset of the element's content, in pixels.

    ScrollHeight

    Number

    The content height of the element.

    ScrollWidth

    Number

    The content width of the element.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get text container attributes.
      const info = await app.ActiveDocument.GetContainerAttributes();
      console.log(info);
    }

ActiveDocument.GetDocumentRange()

Use the GetDocumentRange() method to get the range of the entire document.

Important

This feature is available in JS-SDK v1.1.14 and later.

  • Syntax

    expression.ActiveDocument.GetDocumentRange()

    expression: A variable that represents the Application object.

  • Return value

    Returns a Range object that represents the entire document.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the range for the entire document.
      const range = await app.ActiveDocument.GetDocumentRange();
      console.log(range);
    }

ActiveDocument.GetOperatorsInfo()

Use GetOperatorsInfo() to get information about the current operator.

  • Syntax

    expression.ActiveDocument.GetOperatorsInfo()

    expression: A variable that represents a document type application object.

  • Return value

    Property

    Type

    Description

    type

    String

    The request type.

    response

    Object

    An array of objects, where each object represents a user.

    Each object in the response array has the following properties.

    Property

    Type

    Description

    id

    String

    The user ID.

    avatar_url

    Object

    The URL of the user's avatar.

    logined

    Object

    The user's login status.

    name

    Object

    The user name.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Gets information about the currently logged-in operators.
      const operatorsInfo = await app.ActiveDocument.GetOperatorsInfo();
      console.log(operatorsInfo);
    }

ActiveDocument.GetOnlineCooperatorList()

The GetOnlineCooperatorList() method retrieves a list of online collaborators.

  • Syntax

    expression.ActiveDocument.GetOnlineCooperatorList()

    A variable representing a document application object.

  • Return value

    Array.<Object>

    Property

    Type

    Description

    Avatar

    String

    The user's avatar URL.

    UserName

    String

    The user's name.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Gets a list of online collaborators.
      const operatorsInfo = await app.ActiveDocument.GetOnlineCooperatorList();
      console.log(operatorsInfo);
    }

ActiveDocument.GetViewMode()

GetViewMode() returns the current view mode.

Important

This feature requires JS-SDK v1.1.14 or later.

  • Syntax

    expression.ActiveDocument.GetViewMode()

    expression: An expression that evaluates to a document type application object.

  • Return value

    Returns web for web layout view and pages for page layout view.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the current view mode.
      const mode = await app.ActiveDocument.GetViewMode();
      console.log(mode);
    }

ActiveDocument.GetWatermark()

Use the GetWatermark() method to retrieve the watermark from a secure document.

  • Syntax

    expression.ActiveDocument.GetWatermark()

    expression: A variable representing the application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the watermark from the active document.
      const watermarkInfo = await app.ActiveDocument.GetWatermark();
      console.log(watermarkInfo);
    }

ActiveDocument.ImportDataIntoFields()

The ImportDataIntoFields() method lets you match and replace content in a document based on the input data and configurations.

  • Syntax

    expression.ActiveDocument.ImportDataIntoFields({ Data, Options })

    expression: A variable that represents the Application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Data

    Object

    Yes

    An object that contains the data to import. It can include single, multiple, or nested fields. For nested fields, the keys are concatenated to match the corresponding content controls.

    Important

    Currently, only the Data: { content: value } format is supported.

    Options

    Object

    No

    An object that specifies the import configuration. Currently, only Options: { keyword: 1} is supported.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Finds matching content controls using Data and Options, and replaces their content.
      // If a matching content control is not found, the text is inserted at the end of the document.
      // This example assumes a content control with the title "jssdk" exists in the document.
      await app.ActiveDocument.ImportDataIntoFields({
        Data: {
          'jssdk': 'jssdk2',
        },
        Options: {
          keyword: 1,
        },
      });
    }

ActiveDocument.ReplaceText()

The ReplaceText() method lets you find and replace text throughout the document using an array.

Important

This feature is available in JS-SDK version 1.1.10 and later.

  • Syntax

    expression.ActiveDocument.ReplaceText(Array<Object>)

    expression: A variable that represents the application object.

  • Parameters

    • An array of objects, where each object defines a text replacement operation.

      Property

      Type

      Required

      Description

      list

      Array<Object>

      Yes

      A list of text replacement operations.

    • List object properties

      Property

      Type

      Required

      Description

      key

      String

      Yes

      The text string to replace.

      value

      String

      Yes

      The replacement text.

      options

      Object

      No

      The replacement configuration object.

    • Options object properties

      Property

      Type

      Required

      Description

      isWildcardMatched

      Boolean

      No

      Specifies whether to use wildcards. The asterisk (*) and question mark (?) are supported.

      • Asterisk (*): Matches any sequence of characters.

      • Question mark (?): Matches any single character. A character must be present in this position.

      Valid values:

      • true: Enables wildcard matching.

      • false (default): Disables wildcard matching.

      isCaseSensitive

      Boolean

      No

      Specifies whether the match is case-sensitive. Valid values:

      • true (default): The match is case-sensitive.

      • false: The match is not case-sensitive.

      isWholeWordMatched

      Boolean

      No

      Specifies whether to match whole words only. Valid values:

      • true (default): Matches whole words only.

      • false: Allows partial word matches.

      isWidthIgnored

      Boolean

      No

      Specifies whether to ignore the difference between full-width and half-width characters. Valid values:

      • true (default): Ignores character width.

      • false: Distinguishes between full-width and half-width characters.

  • Return value

    A return value of true indicates a successful replacement, and false indicates a failed replacement.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Replace text
      const isSuccess = await app.ActiveDocument.ReplaceText([
        {
          key: 'Aliyun',
          value: 'js-sdk',
        },
      ]);
      console.log(isSuccess); // true
    }

ActiveDocument.Save()

The Save() method saves changes to the document.

Important

This feature requires JS-SDK v1.1.10 or later.

  • Syntax

    expression.ActiveDocument.Save()

    expression: An expression that represents a document object.

  • Return value

    Property

    Type

    Description

    result

    String

    The save status.

    size

    Number

    The file size, in bytes.

    version

    Number

    The version number.

    Save status descriptions

    Save status

    Description

    ok

    The version is saved. You can view it in Version History.

    nochange

    The file has no changes to save.

    SavedEmptyFile

    The save operation resulted in an empty file. Saving empty files is not supported.

    SpaceFull

    The disk space is full.

    QueueFull

    The server's save queue is full, possibly due to frequent save operations. Your request has been enqueued.

    fail

    The save operation failed.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Save the active file.
      const save = await app.ActiveDocument.Save();
      console.log(save);
    }

ActiveDocument.SetReadOnly()

Use the SetReadOnly() method to temporarily set the active document to read-only.

Important
  • This feature is available in JS-SDK V1.1.10 and later.

  • The read-only status is a temporary local state that applies only to the document in the current tab and resets on page refresh.

  • You must have edit permission to temporarily set a document to read-only.

  • Users with only read-only permissions cannot make a document editable.

  • Syntax

    expression.ActiveDocument.SetReadOnly({ Value })

    expression: An expression that represents the application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Value

    Boolean

    Yes

    Specifies whether to set the document to read-only. Valid values:

    • true: Sets the document to read-only.

    • false: Makes the document editable.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Set the document to read-only.
      await app.ActiveDocument.SetReadOnly({
        Value: true,
      });
    }

ActiveDocument.ScrollTo()

Use the ScrollTo() method to scroll the text container to a specified position.

Important

Available in JS-SDK v1.1.14 and later.

  • Syntax

    expression.ActiveDocument.ScrollTo({ ScrollLeft, ScrollTop })

    expression: An expression that evaluates to the application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    ScrollLeft

    Number

    Yes

    The number of pixels to scroll the content horizontally.

    ScrollTop

    Number

    Yes

    The number of pixels to scroll the content vertically.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Scrolls the active document to the specified position.
      await app.ActiveDocument.ScrollTo({ ScrollLeft: 0, ScrollTop: 20 });
    }

ActiveDocument.SetCommentEnabled()

The SetCommentEnabled() method shows or hides the comment feature (this currently only applies to mobile devices).

Important

This feature is available in JS-SDK v1.1.14 and later.

  • Syntax

    expression.ActiveDocument.SetCommentEnabled({ Enable })

    expression: A document type application object.

  • Parameter

    Parameter

    Type

    Required

    Description

    Enable

    Boolean

    Yes

    Controls the visibility of comments. Valid values are:

    • true: Hides comments.

    • false: Shows comments.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Hide comments.
      await app.ActiveDocument.SetCommentEnabled({
        Enable: true,
      });
    }

ActiveDocument.SetWatermark()

The SetWatermark() method adds a watermark to a document.

  • Syntax

    expression.ActiveDocument.SetWatermark({ Type, Value, FillStyle, Font, Rotate, Horizontal, Vertical })

    expression: The document application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Type

    Number

    Yes

    Specifies whether to add or remove a watermark. Valid values:

    • 1: Adds a watermark.

    • 0: Removes the watermark.

    Value

    String

    Yes

    The watermark text.

    FillStyle

    Object

    No

    The fill style of the watermark.

    Font

    Object

    No

    The font of the watermark.

    Rotate

    Number

    No

    The rotation angle of the watermark.

    Horizontal

    Number

    No

    The horizontal offset of the watermark.

    Vertical

    Number

    No

    The vertical offset of the watermark.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Add a watermark to the safe document.
      await app.ActiveDocument.SetWatermark({
        Type: 1,
        Value: 'WebOffice',
        FillStyle: 'rgba(192, 192, 192, 0.6)',
        Font: 'bold 20px Serif',
        Rotate: -45 * Math.PI / 180,
        Horizontal: 50,
        Vertical: 100,
      });
    }

ActiveDocument.SwitchFileName()

Use the SwitchFileName() method to show or hide the file name column.

Important
  • This feature requires JS-SDK V1.1.10 or later.

  • In web layout view, the file name column appears at the top of the content.

  • This method works only in web layout view.

  • Syntax

    expression.ActiveDocument.SwitchFileName(Boolean)

    expression: Represents the document type application object.

  • Parameters

    Boolean: true displays the file name column; false hides it.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Switch to the web layout view.
      await app.ActiveDocument.SwitchTypoMode(true);
    
      // Hide the file name column.
      await app.ActiveDocument.SwitchFileName(false);
    }

ActiveDocument.SwitchTypoMode()

The SwitchTypoMode() method toggles between page layout view and web layout view.

Important

This feature requires JS-SDK v1.1.10 or later.

  • Syntax

    expression.ActiveDocument.SwitchTypoMode(Boolean)

    expression: A variable that represents the Application object.

  • Parameters

    A Boolean that specifies the view mode: true for web layout view, or false for page layout view.

  • Return value

    Returns a Boolean value: true for success, or false for failure.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Switch to page layout view.
      await app.ActiveDocument.SwitchTypoMode(false);
    }

ActiveDocument.GetMissingFontList()

The GetMissingFontList() method returns a list of all missing fonts.

  • Syntax

    expression.ActiveDocument.GetMissingFontList()

    expression: A document type application object

  • Return value

    A list of missing fonts

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      const list = await app.ActiveDocument.GetMissingFontList();
      console.log('list: ', list);
    }

ActiveDocument.Protect({ Password })

Use the Protect() method to restrict editing.

  • Syntax

    expression.ActiveDocument.Protect({ Password })

    expression: A variable that represents the Application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Password

    String

    No

    The password used to restrict editing.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Enable editing restriction.
      await app.ActiveDocument.Protect('test');
    
      // Disable editing restriction.
      await app.ActiveDocument.Unprotect('test');
    }

ActiveDocument.Unprotect({ Password })

The UnProtect() method disables editing restrictions.

  • Syntax

    expression.ActiveDocument.Unprotect({ Password })

    Expression: A variable that represents the application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Password

    String

    No

    The password required to disable the editing restriction.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Enable editing restriction.
      await app.ActiveDocument.Protect('test');
    
      // Disable editing restriction.
      await app.ActiveDocument.Unprotect('test');
    }

ActiveDocument.SetContentControlAuthority({ DefaultPermission, Permissions })

The SetContentControlAuthority() method sets a content control to read-only.

  • Syntax

    expression.ActiveDocument.SetContentControlAuthority({ DefaultPermission, Permissions })

    expression: A variable that represents the application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    DefaultPermission

    String

    No

    Specifies the default permission for content controls. Valid values:

    • read: read-only permission.

    • edit: edit permission.

    Permissions

    Array.<Object>

    No

    An array of objects that sets permissions for individual content controls.

    Permissions object

    Parameter

    Type

    Required

    Description

    tag

    String

    Yes

    The tag of the content control.

    access

    String

    Yes

    Specifies the permission for the content control. Valid values:

    • read: read-only permission.

    • edit: edit permission.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Enable editing restriction.
      await app.ActiveDocument.Protect();
    
      // Sets the default permission for content controls to read-only, and grants edit permission to the control with the 'test' tag.
      await app.ActiveDocument.SetContentControlAuthority({ DefaultPermission: 'read', Permissions: [{ tag: 'test', access: 'edit' }] });
    }

ActiveDocument.SetScrollBarStyle({ BackgroundColor, HoverBackgroundColor, ScrollBarWidth, BorderRadius })

Use the SetScrollBarStyle() method to set the scrollbar style.

Important

This feature is only supported in WebKit-based browsers.

  • Syntax

    expression.ActiveDocument.SetScrollBarStyle({ BackgroundColor, HoverBackgroundColor, ScrollBarWidth, BorderRadius })

    expression: The Application object.

  • Parameter

    An object that specifies the scrollbar style.

    Parameter

    Type

    Required

    Description

    BackgroundColor

    String

    No

    Background color of the scrollbar.

    HoverBackgroundColor

    String

    No

    Background color of the scrollbar on hover.

    ScrollBarWidth

    Number

    No

    Width of the scrollbar. Valid values: 0–100.

    BorderRadius

    Number

    No

    Border radius of the scrollbar. Must be 0 or greater.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Set the scrollbar style.
      await app.ActiveDocument.SetScrollBarStyle({ BackgroundColor: '#FFFFFF', HoverBackgroundColor: '#ffffff', ScrollBarWidth: 6, BorderRadius: 6 });
    }

ActiveDocument.CustomDocumentProperties.Add()

Use the Add() method to create a custom document property.

Important

This feature is available in JS-SDK v1.1.10 or later.

  • Syntax

    expression.ActiveDocument.CustomDocumentProperties.Add({ Name, Value })

    expression: The application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Name

    String

    Yes

    The custom document property's name.

    Value

    Object

    No

    The custom document property's value.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the custom document properties.
      const DocumentProperties = await app.ActiveDocument.DocumentProperties;
    
      // Create a new custom document property.
      await DocumentProperties.Add({
        Name: 'Aliyun',
        Value: 'test_id',
      })
    }

ActiveDocument.CustomDocumentProperties.CalcDocumentId()

Use the CalcDocumen() method to customize how document IDs are calculated.

Important

This feature requires JS-SDK version 1.1.10 or later.

  • Syntax

    expression.ActiveDocument.CustomDocumentProperties.CalcDocumentId({ FileOId, OrganizationCode, SubDepartment, DocYear, DocumentType, SerialNumber })

    expression: The application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    FileOId

    String

    No

    The OID of the document.

    OrganizationCode

    String

    Yes

    The organization code. Maximum 18 characters.

    SubDepartment

    String

    Yes

    The sub-department code. Maximum 3 characters.

    DocYear

    Number

    Yes

    The document year.

    DocumentType

    String

    Yes

    The document type. Valid values range from 01 to 0F. The default value is 01.

    SerialNumber

    String

    Yes

    The serial number. Maximum 5 characters.

  • Return Value

    Returns the calculated document ID.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Gets the custom document properties.
      const DocumentProperties = await app.ActiveDocument.DocumentProperties;
    
      // Calculates the custom document ID.
      await DocumentProperties.CalcDocumentId({
        FileOId: '1.0.0',
        OrganizationCode: 'Aliyun_Test_Code',
        SubDepartment: '001',
        DocYear: new Date().getFullYear(),
        DocumentType: '01',
        SerialNumber: '00001'
      });
    }

ActiveDocument.Find.Execute()

The Find.Execute() method searches for and highlights text.

  • Syntax

    expression.ActiveDocument.Find.Execute()

    expression: A variable representing a document type application object.

  • Parameters

    Parameter

    Type

    Required

    Description

    Text

    String

    No

    The text to search for.

    ShowHighlight

    Boolean

    No

    Specifies whether to highlight the search results. Valid values:

    • true (default): Highlights the search results.

    • false: Does not highlight the search results.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Search for and highlight text.
      app.ActiveDocument.Find.Execute('test', true);
    }

ActiveDocument.Find.ClearHitHighlight()

To clear the highlight from search results, use the Find.ClearHitHighlight() method.

  • Syntax

    expression.ActiveDocument.Find.ClearHitHighlight()

    expression: A variable that represents an Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Clear search highlights.
      app.ActiveDocument.Find.ClearHitHighlight();
    }

Properties

ActiveDocument.Content

The Content property returns a range object that represents the main story of the document.

Important

This feature requires JS-SDK version 1.1.10 or later.

  • Syntax

    expression.ActiveDocument.Content

    expression: The document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Returns a Range object.
      const Range = await app.ActiveDocument.Content;
    
      // Gets the text content from the Range object.
      const text = await Range.Text;
    }

ActiveDocument.CustomDocumentProperties

The CustomDocumentProperties property returns a collection of custom document properties for the specified document.

Important

This feature requires JS-SDK v1.1.10 or later.

  • Syntax

    expression.ActiveDocument.CustomDocumentProperties

    expression: An object for the document application.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the custom document properties.
      const CustomDocumentProperties = await app.ActiveDocument.CustomDocumentProperties;
    }

ActiveDocument.DocumentFields

Returns a read-only DocumentFields collection containing all fields in the document.

  • Syntax

    expression.ActiveDocument.DocumentFields

    expression: The application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Gets the DocumentFields object.
      const DocumentFields = await app.ActiveDocument.DocumentFields;
    }

ActiveDocument.Fields

Returns a read-only Fields collection representing all fields in the document.

  • Syntax

    expression.ActiveDocument.Fields

    expression: An expression that returns an Application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Returns a Fields object.
      const Fields = await app.ActiveDocument.Fields;
    }

ActiveDocument.Hyperlinks

Returns a read-only Hyperlinks collection of all hyperlinks in the specified document.

  • Syntax

    expression.ActiveDocument.Hyperlinks

    expression: Represents a document type application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Returns a Hyperlinks object.
      const Hyperlinks = await app.ActiveDocument.Hyperlinks;
    }

ActiveDocument.InlineShapes

Returns a read-only collection of all InlineShape objects in the document.

  • Syntax

    expression.ActiveDocument.InlineShapes

    expression: A variable representing the Application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Returns an InlineShapes object.
      const InlineShapes = await app.ActiveDocument.InlineShapes;
    }

ActiveDocument.PageSetup

Returns the PageSetup object for the specified document.

  • Syntax

    expression.ActiveDocument.PageSetup

    expression: The application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Gets the PageSetup object.
      const PageSetup = await app.ActiveDocument.PageSetup;
    }

ActiveDocument.ReadOnly

The ReadOnly property makes the document read-only.

Important

JS-SDK v1.1.14 or later supports this feature.

  • Syntax

    expression.ActiveDocument.ReadOnly

    expression: A variable that represents the Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Gets the document's read-only status.
      const ReadOnly = await app.ActiveDocument.ReadOnly;
    }

ActiveDocument.ReadOnlyComment

This read-only property indicates whether the document is read-only and commentable.

  • Syntax

    expression.ActiveDocument.ReadOnlyComment

    expression: An application object of a document type.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      const ReadOnlyComment = await app.ActiveDocument.ReadOnlyComment;
    }

ActiveDocument.SupportReadOnlyComment

A read-only property that indicates whether the document supports read-only access with comment permissions.

  • Syntax

    expression.ActiveDocument.SupportReadOnlyComment

    expression: A variable that represents an application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      const SupportReadOnlyComment = await app.ActiveDocument.SupportReadOnlyComment;
    }

ActiveDocument.Revisions

This read-only property returns a Revisions collection that represents the tracked changes in a range or document.

  • Syntax

    expression.ActiveDocument.Revisions

    expression: A variable that represents the Application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Gets the Revisions object.
      const Revisions = await app.ActiveDocument.Revisions;
    }

ActiveDocument.Sections

Returns a collection of all sections in the specified document. This is a read-only property.

  • Syntax

    expression.ActiveDocument.Sections

    expression: An expression that returns an Application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      const Sections = await app.ActiveDocument.Sections;
    }

ActiveDocument.Shapes

This read-only property returns a Shapes collection of all Shape objects in the document.

  • Syntax

    expression.ActiveDocument.Shapes

    expression: A variable that represents an Application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Returns a Shapes object.
      const Shapes = await app.ActiveDocument.Shapes;
    }

ActiveDocument.Tables

Returns a read-only collection of all tables in the specified document.

  • Syntax

    expression.ActiveDocument.Tables

    expression: A variable that represents the application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Returns a Tables object.
      const Tables = await app.ActiveDocument.Tables;
    }

ActiveDocument.TrackRevisions

Use TrackRevisions to switch between edit mode and review mode.

Important
  • This feature requires JS-SDK v1.1.10 or later.

  • Checking if the current page is in review mode requires JS-SDK v1.1.15 or later.

  • Syntax

    expression.ActiveDocument.TrackRevisions = Boolean

    expression: The application object.

  • Parameters

    A Boolean value of true switches to review mode, and false switches to edit mode.

  • Examples

    • Switch between review mode and edit mode

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Switch the current document to review mode.
      app.ActiveDocument.TrackRevisions = true;
    }
    • Check whether the document is in review mode

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Check whether the document is in review mode.
      const TrackRevisions = await app.ActiveDocument.TrackRevisions;
      console.log(TrackRevisions);
    }

ActiveDocument.ActiveWindows

This read-only property returns a Windows collection containing all windows in the document.

  • Syntax

    expression.ActiveDocument.ActiveWindows

    expression: An Application object.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Returns a Windows object.
      const Windows = await app.ActiveDocument.ActiveWindows;
    }

ActiveDocument.Words

The Words property returns a collection of all the words in the document.

Important

Available in JS-SDK V1.1.10 and later.

  • Syntax

    • expression.ActiveDocument.Words

      expression: A variable that represents a document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get all words in the document.
      const Words = await app.ActiveDocument.Words;
    }

ActiveDocument.Words.Count

The Count property returns the word count of the document.

Important

Available in JS-SDK v1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Words.Count

    expression: The application object.

  • Return value

    Parameter

    Type

    Description

    wordCount

    Number

    The total number of words.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the total word count.
      const count = await app.ActiveDocument.Words.Count;
      console.log(count);
    }

ActiveDocument.Find

The Find property returns a Find object whose properties and methods map to the options in the Find and Replace dialog box.

Important

This feature requires JS-SDK version 1.1.10 or later.

  • Syntax

    expression.ActiveDocument.Find

    expression: A variable that represents the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the Find object.
      const Find = await app.ActiveDocument.Find;
    }