Table

Updated at:

This topic describes the APIs for the Table object in text documents.

Tables

ActiveDocument.Tables

Retrieves all tables in the document.

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

  • This feature is supported only on PCs.

  • Syntax

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

Methods

ActiveDocument.Tables.Add()

Use the Add() method to insert a table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Add({ Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior })

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Range

    Object

    Yes

    The location information.

    NumRows

    Number

    Yes

    The number of rows for the new table.

    NumColumns

    Number

    Yes

    The number of columns for the new table.

    DefaultTableBehavior

    Enum

    No

    Specifies whether to automatically resize cells to fit the content. For more information, see WdDefaultTableBehavior.

    AutoFitBehavior

    Enum

    No

    Sets the rules for automatically resizing cells. For more information, see WdAutoFitBehavior.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables in the document.
      const tables = await app.ActiveDocument.Tables;
    
      // Insert a table.
      await tables.Add(
        app.ActiveDocument.ActiveWindow.Selection.Range, // The location information.
        3, // The number of rows for the new table.
        3, // The number of columns for the new table.
        1, // Enable the auto-fit feature.
        1, // Automatically resize the table based on its content.
      );
    
    }

Properties

ActiveDocument.Tables.Count

Use the Count property to retrieve the total number of tables in the document.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Count

    expression represents the application object for the document type.

  • Return value

    Returns a Number that indicates the total number of tables.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables in the document.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the total number of tables.
      const count = await tables.Count;
      console.log(count);
    }

Table

ActiveDocument.Tables.Item()

Retrieves a single table object.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index)

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Index

    Number

    Yes

    The table at the specified index.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables in the document.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    }

Methods

ActiveDocument.Tables.Item(Index).Delete()

Use the Delete() method to delete the specified table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Delete()

    expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables in the document.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Delete the first table.
      await tableOne.Delete();
    }

Cells

ActiveDocument.ActiveWindow.Selection.Cells

Retrieves all cells in the selection.

Important

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

  • Syntax

    • expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells

      or expression.ActiveDocument.Tables.Item(Index).Columns.Item(Index).Cells

      or expression.ActiveDocument.ActiveWindow.Selection.Cells

    • expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the first table.
      const tableOne = await app.ActiveDocument.Tables.Item(1);
    
      // Get all cells in the first row of the table.
      const rowText = await tableOne.Rows.Item(1).Cells;
    
      // Get all cells in the second column of the table.
      const columnText = await tableOne.Columns.Item(2).Cells;
    }

Cell

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item()

Retrieves a single cell object.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index)

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Index

    String

    Yes

    The cell at the specified index.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the first table.
      const tableOne = await app.ActiveDocument.Tables.Item(1);
    
      // Get the first cell in the first row of the table.
      const rowText = await tableOne.Rows.Item(1).Cells.Item(1);
    }

Methods

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Delete()

Use the Delete() method to delete the specified cell.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Delete()

    Expression: Document-type application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the first table.
      const tableOne = await app.ActiveDocument.Tables.Item(1);
    
      // Get the first cell in the first row of the table.
      const cellOne = await tableOne.Rows.Item(1).Cells.Item(1);
      
      // Delete the cell.
      await cellOne.Delete();
    }

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).SetHeight()

Use the SetHeight() method to set the height of the row that contains the specified cell.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).SetHeight({ RowHeight, HeightRule })

    Expression: Document-type application object

  • Parameters

    Property

    Data type

    Required

    Description

    RowHeight

    Number

    Yes

    The height of the row, in points.

    HeightRule

    Enum

    No

    The rule for determining the row height. For more information, see WdRowHeightRule.

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).SetWidth()

Use the SetWidth() method to set the width of the column that contains the specified cell.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).SetWidth({ ColumnWidth, RulerStyle })

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    ColumnWidth

    Number

    Yes

    The width of the column, in points.

    RulerStyle

    Enum

    No

    Controls how text adjusts the cell width. For more information, see WdRulerStyle.

Properties

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range

Use the Range property to retrieve the Range object that represents the part of the document within the specified cell.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells.Item(Index).Range

    expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get the first cell in the first row of the table.
      const cell = await tableOne.Rows.Item(1).Cells.Item(1);
    
      // Get the Range object for the part of the document within the cell.
      const range = await cell.Range;
    }

Columns

ActiveDocument.Tables.Item(Index).Columns

Retrieves all columns in the specified table.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Columns

    Expression: Document Type.Application.Object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all columns in the table.
      const columns = tableOne.Columns;
    }

Methods

ActiveDocument.Tables.Item(Index).Columns.Add()

Use the Add() method to insert a column into the specified table.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Columns.Add({ BeforeColumn })

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    BeforeColumn

    Number

    Yes

    The Column object that will appear to the right of the new column.

  • Parameter

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all columns in the table.
      const columns = await tableOne.Columns;
    
      // Insert a column.
      await columns.Add(1);
    }

Properties

ActiveDocument.Tables.Item(Index).Columns.Count

Use the Count property to retrieve the total number of columns in the specified table.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Columns.Count

    Expression: Application object of the document type

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all columns in the table.
      const columns = await tableOne.Columns;
    
      // Get the total number of columns in the table.
      const count = await columns.Count;
      console.log(count);
    }

Column

ActiveDocument.Tables.Item(Index).Columns.Item()

Retrieves a specific column from the table.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Columns.Item(Index)

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Index

    Number

    Yes

    The index of the column.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all columns in the table.
      const columns = await tableOne.Columns;
    
      // Get the first column of the table.
      const columnOne = await columns.Item(1);
    }

Methods

ActiveDocument.Tables.Item(Index).Columns.Item(Index).Delete()

Use the Delete() method to delete the specified column.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Columns.Item(Index).Delete()

    expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all columns in the table.
      const columns = await tableOne.Columns;
    
      // Get the first column of the table.
      const columnOne = await columns.Item(1);
    
      // Delete the first column.
      columnOne.Delete();
    }

ActiveDocument.Tables.Item(Index).Columns.Item(Index).SetWidth()

Use the SetWidth() method to set the width of the specified column.

Important

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

  • Procedure

    expression.ActiveDocument.Tables.Item(Index).Columns.Item(Index).SetWidth({ ColumnWidth, RulerStyle })

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    ColumnWidth

    Number

    Yes

    The width of the specified column, in points.

    RulerStyle

    Enum

    No

    Controls how text adjusts the cell width. For more information, see WdRulerStyle.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all columns in the table.
      const columns = await tableOne.Columns;
    
      // Get the first column of the table.
      const columnOne = await columns.Item(1);
    
      // Set the width of the first column.
      columnOne.SetWidth(50);
    }

Properties

ActiveDocument.Tables.Item(Index).Columns.Item(Index).Cells

Use the Cells property to retrieve all cells in the specified column of the table.

Important

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

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Columns.Item(Index).Cells

    Expression: Application object for the document type

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all columns in the table.
      const columns = await tableOne.Columns;
    
      // Get the first column of the table.
      const columnOne = await columns.Item(1);
    
      // Get all cells in the first column.
      const cells = columnOne.Cells;
    }

Rows

ActiveDocument.Tables.Item(Index).Rows

Retrieves all rows in the specified table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows

    expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the first table.
      const rows = tableOne.Rows;
    }

Methods

ActiveDocument.Tables.Item(Index).Rows.Add()

Use the Add() method to insert a row at a specified location.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Add({ BeforeRow })

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    BeforeRow

    Number

    Yes

    The Row object that will appear below the new row.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the table.
      const rows = await tableOne.Rows;
    
      // Insert a row.
      await rows.Add(1);
    }

Properties

ActiveDocument.Tables.Item(Index).Rows.Count

Use the Count property to retrieve the total number of rows in the specified table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Count

    expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the table.
      const rows = await tableOne.Rows;
    
      // Get the total number of rows in the table.
      const count = await rows.Count;
      console.log(count);
    }

Row

ActiveDocument.Tables.Item(Index).Rows.Item()

Retrieves a specific row from the table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index)

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    Index

    Number

    Yes

    Row index.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the table.
      const rows = await tableOne.Rows;
    
      // Get the first row of the table.
      const rowOne = await rows.Item(1);
    }

Methods

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Delete()

Use the Delete() method to delete the specified row from the table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Delete()

    Expression: Document-Typed Application Object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the table.
      const rows = await tableOne.Rows;
    
      // Get the first row of the table.
      const rowOne = await rows.Item(1);
    
      // Delete the first row.
      rowOne.Delete();
    }

ActiveDocument.Tables.Item(Index).Rows.Item(Index).SetHeight()

Use the SetHeight() method to set the height of the specified row in the table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).SetHeight({ RowHeight, HeightRule })

    expression represents the application object for the document type.

  • Parameters

    Property

    Data type

    Required

    Description

    RowHeight

    Number

    Yes

    The height of the specified row, in points.

    HeightRule

    Enum

    No

    The rule for determining the height of the specified row. For more information, see WdRowHeightRule.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the table.
      const rows = await tableOne.Rows;
    
      // Get the first row of the table.
      const rowOne = await rows.Item(1);
    
      // Set the height of the first row.
      rowOne.SetHeight(50);
    }

Properties

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells

Use the Cells property to retrieve all cells in the specified row of the table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Cells

    expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the table.
      const rows = await tableOne.Rows;
    
      // Get the first row of the table.
      const rowOne = await rows.Item(1);
    
      // Get all cells in the first row.
      const cells = rowOne.Cells;
    }

ActiveDocument.Tables.Item(Index).Rows.Item(Index).Range

Use the Range property to retrieve the Range object that represents the part of the document within the specified row of the table.

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

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Tables.Item(Index).Rows.Item(Index).Range

    expression represents the application object for the document type.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all tables.
      const tables = await app.ActiveDocument.Tables;
    
      // Get the first table.
      const tableOne = await tables.Item(1);
    
      // Get all rows in the table.
      const rows = await tableOne.Rows;
    
      // Get the first row of the table.
      const rowOne = await rows.Item(1);
    
      // Get the Range object of the first row.
      const range = rowOne.Range;
    }