Field

Updated at:

This topic describes the APIs related to the Field object in text documents.

Fields

ActiveDocument.Fields

Retrieves all fields in a document.

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

  • In the current version of text documents, call this API only after using the at sign (@) plugin.

  • Syntax

    expression.ActiveDocument.Fields

    expression is the application object for the document type.

  • Example

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

Methods

ActiveDocument.Fields.List()

Returns a list of all fields in the document.

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

  • In the current version of text documents, call this API only after using the at sign (@) plugin. An item is created each time you insert an at sign (@).

  • Syntax

    expression.ActiveDocument.Fields.List()

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get all fields in the document.
      const Fields = await app.ActiveDocument.Fields;
    
      // Get a list of all fields in the document.
      const List = await Fields.List;
      console.log(List);
    }

Field

ActiveDocument.Fields.Item()

Retrieves a single field object.

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

  • In the current version of text documents, call this API only after using the at sign (@) plugin. An item is created each time you insert an at sign (@).

  • Syntax

    expression.ActiveDocument.Fields.Item(Index)

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get all fields in the document.
      const Fields = await app.ActiveDocument.Fields;
    
      // Get a single Field object.
      const Field = await Fields.Item(1);
    }

Properties

ActiveDocument.Fields.Item(Index).Code

Returns the code of a single field in the document.

Important

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

  • Syntax

    expression.ActiveDocument.Fields.Item(Index).Code

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get all fields in the document.
      const Fields = await app.ActiveDocument.Fields;
    
      // Get a single Field object.
      const Field = await Fields.Item(1);
    
      // Get the code of the field.
      const Code = await Field.Code;
      console.log(Code);
    }

ActiveDocument.Fields.Item(Index).Type

Returns the type of a single field in the document.

Important

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

  • Syntax

    expression.ActiveDocument.Fields.Item(Index).Type

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get all fields in the document.
      const Fields = await app.ActiveDocument.Fields;
    
      // Get a single Field object.
      const Field = await Fields.Item(1);
    
      // Get the type of the field.
      const Type = await Field.Type;
      console.log(Type);
    }

DocumentFields

ActiveDocument.DocumentFields

Retrieves all document fields in a document.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all document fields.
      const documentFields = await app.ActiveDocument.DocumentFields;
    }

Methods

ActiveDocument.DocumentFields.Add()

Inserts a document field.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Add({ Name, Range, Hidden, PrintOut, ReadOnly })

    expression is the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Name

    String

    Yes

    The name of the document field.

    Range

    Object

    Yes

    The range of the document field.

    Hidden

    Boolean

    No

    Specifies whether to hide the document field. Valid values:

    • false (default): The field is visible.

    • true: The field is hidden.

    PrintOut

    Boolean

    No

    Specifies whether the document field is printable. Valid values:

    • true (default): The field is printable.

    • false: The field is not printable.

    ReadOnly

    Boolean

    No

    Specifies whether the document field is read-only. Valid values:

    • false (default): The field is editable.

    • true: The field is read-only.

  • Range description

    Property

    Data type

    Required

    Description

    Start

    Number

    Yes

    The start position.

    End

    Number

    Yes

    The end position.

  • Return value

    Property

    Data type

    Description

    params1

    String

    Description of return value 1.

    params2

    Number

    Description of return value 2.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: false, // Set the document field to be visible.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    }

ActiveDocument.DocumentFields.AddDocumentFields()

Bulk-inserts document fields.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.AddDocumentFields()

    expression is the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Name

    String

    Yes

    The name of the document field.

    Range

    Object

    Yes

    The range of the document field.

    Hidden

    Boolean

    No

    Specifies whether to hide the document field. Valid values:

    • false (default): The field is visible.

    • true: The field is hidden.

    PrintOut

    Boolean

    No

    Specifies whether the document field is printable. Valid values:

    • true (default): The field is printable.

    • false: The field is not printable.

    ReadOnly

    Boolean

    No

    Specifies whether the document field is read-only. Valid values:

    • false (default): The field is editable.

    • true: The field is read-only.

    Value

    String

    No

    The value of the field.

  • Range description

    Property

    Data type

    Required

    Description

    Start

    Number

    Yes

    The start position.

    End

    Number

    Yes

    The end position.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Bulk-insert document fields.
      await app.ActiveDocument.DocumentFields.AddDocumentFields([
        {
          Name: '1', // Set the name of the document field.
          Range: { Start: 0, End: 10 }, // Set the position of the document field.
          Value: 'WebOffice1', // Set the value of the document field.
        },
        {
          Name: '2', // Set the name of the document field.
          Range: { Start: 12, End: 18 }, // Set the position of the document field.
          Value: 'WebOffice2', // Set the value of the document field.
        },
      ]);
    }

ActiveDocument.DocumentFields.Exists()

Checks whether a document field exists.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Exists({ Name })

    expression is the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Name

    String

    Yes

    The name of the document field.

  • Return value

    Returns a Boolean value that indicates whether the document field exists.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Bulk-insert document fields.
      await app.ActiveDocument.DocumentFields.AddDocumentFields([
        {
          Name: '1', // Set the name of the document field.
          Range: { Start: 0, End: 10 }, // Set the position of the document field.
          Value: 'WebOffice1', // Set the value of the document field.
        },
        {
          Name: '2', // Set the name of the document field.
          Range: { Start: 12, End: 18 }, // Set the position of the document field.
          Value: 'WebOffice2', // Set the value of the document field.
        },
      ]);
    
      // Check whether a document field exists.
      const hasOne = await app.ActiveDocument.DocumentFields.Exists('1');
      console.log(hasOne); 
    }

ActiveDocument.DocumentFields.GetAllNames()

Returns the names of all document fields.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.GetAllNames()

    expression is the application object for the document type.

  • Return value

    Returns an Array that contains the names of all document fields.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Bulk-insert document fields.
      await app.ActiveDocument.DocumentFields.AddDocumentFields([
        {
          Name: '1', // Set the name of the document field.
          Range: { Start: 0, End: 10 }, // Set the position of the document field.
          Value: 'WebOffice1', // Set the value of the document field.
        },
        {
          Name: '2', // Set the name of the document field.
          Range: { Start: 12, End: 18 }, // Set the position of the document field.
          Value: 'WebOffice2', // Set the value of the document field.
        },
      ]);
    
      // Get the names of all document fields.
      const names = await app.ActiveDocument.DocumentFields.GetAllNames();
      console.log(names);
    }

ActiveDocument.DocumentFields.SetDocumentFieldsValues()

Replaces the content of multiple document fields in a batch.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.SetDocumentFieldsValues({Value, Data})

expression is the application object for the document type.

  • Parameters

Property

Data type

Required

Description

Value

String

Yes

The content for batch replacement.

Data

Array.<Object>

Yes

The index or name of the document field.

  • Data description

Property

Data type

Required

Description

Index

Number

Specify either Index or Name.

The sequence number.

Name

String

Specify either Index or Name.

The name.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
       const dfs = [
            {
                Name: '2',
                Range: { Start: 30, End: 31 },
                Value: '2',
            },
            {
                Name: '3',
                Range: { Start: 33, End: 34 },
                Value: '3',
            },
            {
                Name: '4',
                Range: { Start: 35, End: 36 },
                Value: '4',
            }];
        await app.ActiveDocument.DocumentFields.AddDocumentFields(dfs);
        await app.ActiveDocument.DocumentFields.SetDocumentFieldsValues({ Value: "Batch replace document fields", Arrays: [{Name: '2'}, {Name: '3'}, {Name: '4'}] });
    
    }

Properties

ActiveDocument.DocumentFields.Count

Returns the number of document fields.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Count

    expression is the application object for the document type.

  • Return value

    Returns a Number that indicates the number of document fields.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the number of document fields.
      const count = app.ActiveDocument.DocumentFields.Count;
      console.log(count);
    }

ActiveDocument.DocumentFields.Display

Gets or sets the display mode for document field hints.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Display

    expression is the application object for the document type.

  • Return value

    Returns a Number that indicates the display mode for document field hints. For more information about the types of document field hints, see WdDisplayDocumentFields.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Set the display mode for document field hints.
      app.ActiveDocument.DocumentFields.Display = instance.Enum.WdDisplayDocumentFields.wpsDisplayDocumentFields;
    }

DocumentField

ActiveDocument.DocumentFields.Item()

Retrieves a single document field object.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name })

    expression is the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Index

    Number

    No

    The index of the document field.

    Name

    String

    No

    The name of the document field.

  • Return value

    Returns a DocumentField object that represents a single document field.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: false, // Set the document field to be visible.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
      console.log(documentField);
    }

Methods

ActiveDocument.DocumentFields.Item({ Index, Name }).Delete()

Deletes a single document field.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).Delete()

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: false, // Set the document field to be visible.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Delete the document field.
      await documentField.Delete();
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).GotoBegin()

Moves the cursor to the start position of a document field.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).GotoBegin()

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: false, // Set the document field to be visible.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Move the cursor to the start position of the document field.
      await documentField.GotoBegin();
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).GotoEnd()

Moves the cursor to the end position of a document field.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).GotoEnd()

    expression is the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: false, // Set the document field to be visible.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Move the cursor to the end position of the document field.
      await documentField.GotoEnd();
    }

Properties

ActiveDocument.DocumentFields.Item({ Index, Name }).Hidden

Indicates whether a document field is hidden.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).Hidden

    expression is the application object for the document type.

  • Return value

    Returns a Boolean value that indicates whether the document field is hidden.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: true, // Set the document field to be hidden.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Check whether the document field is hidden.
      const isHidden = await documentField.Hidden;
      console.log(isHidden);
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).Name

Returns the name of a document field.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).Name

    expression is the application object for the document type.

  • Return value

    Returns a String that indicates the name of the document field.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: true, // Set the document field to be hidden.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
      console.log(documentField);
    
      // Get the name of the document field.
      const name = await documentField.Name;
      console.log(name);
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).PrintOut

Indicates whether a document field is printable.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).PrintOut

    expression is the application object for the document type.

  • Return value

    Returns a Boolean value that indicates whether the document field is printable.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: false, // Set the document field to be visible.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Check whether the document field is printable.
      const isPrintOut = await documentField.PrintOut;
      console.log(isPrintOut);
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).Range

Returns the range of a document field.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).Range

    expression is the application object for the document type.

  • Return value

    Returns a Range object that represents the range of the document field.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: false, // Set the document field to be visible.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Get the range of the document field.
      const range = await documentField.Range;
      console.log(range);
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).ReadOnly

Indicates whether a document field is read-only.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).ReadOnly

    expression is the application object for the document type.

  • Return value

    Returns a Boolean value that indicates whether the document field is read-only.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: true, // Set the document field to be hidden.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Check whether the document field is read-only.
      const isReadOnly = await documentField.ReadOnly;
      console.log(isReadOnly);
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).Style

Returns the style of a document field.

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).Style

    expression is the application object for the document type.

  • Return value

    Returns a Style object that represents the style of the document field.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: true, // Set the document field to be hidden.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Get the style of the document field.
      const style = await documentField.Style;
      console.log(style);
    }

ActiveDocument.DocumentFields.Item({ Index, Name }).Value

Returns the value of a document field.

Important

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

  • Syntax

    expression.ActiveDocument.DocumentFields.Item({ Index, Name }).Value

    expression is the application object for the document type.

  • Return value

    Returns a String that indicates the value of the document field.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Insert a document field.
      await app.ActiveDocument.DocumentFields.Add({
        Name: '1',
        Range: { Start: 12, End: 20 },
        Hidden: true, // Set the document field to be hidden.
        PrintOut: true, // Set the document field to be printable.
        ReadOnly: true, // Set the document field to be read-only.
      });
    
      // Get a single document field object.
      const documentField = await app.ActiveDocument.DocumentFields.Item('1');
    
      // Get the value of the document field.
      const value = await documentField.Value;
      console.log(value);
    }