ActiveSheet

Updated at:

This topic describes the APIs related to the ActiveSheet object in spreadsheets.

ActiveSheet

ActiveWorkbook.ActiveSheet

Returns the active worksheet in the active workbook.

Important

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

  • Syntax

    expression.ActiveWorkbook.ActiveSheet

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active workbook.
      const activeWorkbook = await app.ActiveWorkbook;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await activeWorkbook.ActiveSheet;
    }

Methods

ActiveWorkbook.ActiveSheet.Delete()

Use the Delete() method to delete the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Delete()

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Delete the active worksheet.
      await activeSheet.Delete();
    }

ActiveWorkbook.ActiveSheet.ExportAsFixedFormat()

Use the ExportAsFixedFormat() method to export the active worksheet as a PDF or image file and return the URL of the exported file.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.ExportAsFixedFormat({ Type })

    Expression: document type, Application object

  • Parameters

    Property

    Data type

    Required

    Description

    Type

    Enum

    No

    The export file type. Supported values: image and PDF. For more information, see XlFixedFormatType.

  • Return value

    Returns the URL of the exported file.

  • Examples

    • Export as PDF

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
      
        // Export the active worksheet as a PDF file and get the URL.
        const pdfUrl = await app.ActiveWorkbook.ActiveSheet.ExportAsFixedFormat();
        console.log(pdfUrl);
      }
    • Export as image

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
      
        // Export the active worksheet as an image and get the URL.
        const imageUrl = await app.ActiveWorkbook.ActiveSheet.ExportAsFixedFormat({
          Type: app.Enum.XlFixedFormatType.xlTypeIMG,
        });
        console.log(imageUrl);
      }

ActiveWorkbook.ActiveSheet.Protect()

Use the Protect() method to protect the active worksheet from modification.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Protect({ Password, DrawingObjects, Scenarios, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables })

    Expression: document type, Application object

  • Parameters

    Property

    Data type

    Required

    Description

    Password

    String

    No

    The worksheet password. This string is case-sensitive.

    • If omitted, the worksheet can be unprotected without a password.

    • If set, the password is required to unprotect the worksheet.

    Important

    Record the password. If you forget it, you cannot unprotect the worksheet.

    DrawingObjects

    Boolean

    No

    Whether to protect shapes in the worksheet. Valid values:

    • false (default): Shapes are not protected.

    • true: Shapes are protected.

    Scenarios

    Boolean

    No

    Whether to protect scenarios in the worksheet. Valid values:

    • true (default): Scenarios are protected.

    • false: Scenarios are not protected.

    AllowFormattingCells

    Boolean

    No

    Whether to allow users to format cells on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed.

    AllowFormattingColumns

    Boolean

    No

    Whether to allow users to format columns on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed.

    AllowFormattingRows

    Boolean

    No

    Whether to allow users to format rows on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed.

    AllowInsertingColumns

    Boolean

    No

    Whether to allow users to insert columns on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed.

    AllowInsertingRows

    Boolean

    No

    Whether to allow users to insert rows on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed.

    AllowInsertingHyperlinks

    Boolean

    No

    Whether to allow users to insert hyperlinks on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed.

    AllowDeletingColumns

    Boolean

    No

    Whether to allow users to delete columns on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed. Each cell in the columns to be deleted must be unlocked.

    AllowDeletingRows

    Boolean

    No

    Whether to allow users to delete rows on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed. Each cell in the rows to be deleted must be unlocked.

    AllowSorting

    Boolean

    No

    Whether to allow users to sort data on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed. Each cell in the sort range must be unlocked or unprotected.

    AllowFiltering

    Boolean

    No

    Whether to allow users to set filters on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed. Users can set or change the filter criteria on an existing AutoFilter, but cannot enable or disable an AutoFilter.

    AllowUsingPivotTables

    Boolean

    No

    Whether to allow users to use pivot tables on the protected worksheet. Valid values:

    • false (default): Not allowed.

    • true: Allowed.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Protect the worksheet with a password.
      activeSheet.Protect('123456');
    }

ActiveWorkbook.ActiveSheet.Unprotect()

Use the Unprotect() method to remove protection from the active worksheet. Has no effect if the worksheet is not protected.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Unprotect({ Password })

    Expression: document type, Application object

  • Parameters

    Property

    Data type

    Required

    Description

    Password

    String

    No

    The password set when the worksheet was protected.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Remove worksheet protection.
      activeSheet.Unprotect('123456');
    }

ActiveWorkbook.ActiveSheet.Move()

Use the Move() method to move the active worksheet to a new position.

Important

This feature is available in JS-SDK V1.1.12 and later.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Move({ Before, After })

    Expression: document type, Application object

  • Parameters

    Property

    Data type

    Required

    Description

    Before

    number

    No

    The ID of the worksheet before which to move the active sheet. Mutually exclusive with After.

    After

    number

    No

    The ID of the worksheet after which to move the active sheet. Mutually exclusive with Before.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Move the first sheet to a position after the second sheet.
      await app.ActiveWorkbook.Sheets(1).Move({
        Before: null,
        After: await app.ActiveWorkbook.Sheets(2).Id,
      });
    }

ActiveWorkbook.ResetClipBoard()

Use the ResetClipBoard() method to clear the copy marquee (marching ants) from the spreadsheet.

  • Syntax

    expression.ActiveWorkbook.ResetClipBoard({ Range })

    Expression: document type, Application object

  • Example

    //@file=base.xlsx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      const range = await app.Selection;
      // Clear the copy marquee.
      await app.ActiveWorkbook.ResetClipBoard()
    }

Properties

ActiveWorkbook.ActiveSheet.Cells

Note

Returns a Range object that represents all the cells on the worksheet. For more information, see Range (area).

Use the Cells property to return all cells in the active worksheet as a Range object.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Cells

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get all cells in the active worksheet.
      const cells = await activeSheet.Cells;
    }

ActiveWorkbook.ActiveSheet.Columns

Note

Returns a Range object that represents all the columns on the worksheet. For more information, see Range (area).

Use the Columns property to return all columns in the active worksheet as a Range object.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Columns

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get all columns in the active worksheet.
      const columns = await activeSheet.Columns;
    }

ActiveWorkbook.ActiveSheet.Index

Use the Index property to retrieve the index number of the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Index

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get the index number of the active worksheet.
      const index = await activeSheet.Index;
      console.log(index);
    }

ActiveWorkbook.ActiveSheet.Name

Use the Name property to retrieve the name of the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Name

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get the name of the active worksheet.
      const name = await app.ActiveWorkbook.ActiveSheet.Name;
      console.log(name);
    }

ActiveWorkbook.ActiveSheet.Names

Use the Names property to retrieve all worksheet-specific names in the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Names

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get all worksheet-specific names in the active worksheet.
      const names = await activeSheet.Names;
    }

ActiveWorkbook.ActiveSheet.Range

Use the Range property to retrieve a cell, a row, a column, or a selection of cells in the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Range

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get a specific cell range from the active worksheet.
      const range = await app.Range('A1');
    }

ActiveWorkbook.ActiveSheet.Rows

Use the Rows property to return all rows in the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Rows

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get all rows in the active worksheet.
      const rows = await activeSheet.Rows;
    }

ActiveWorkbook.ActiveSheet.Shapes

Use the Shapes property to return all shape objects in the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Shapes

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get all shape objects in the active worksheet.
      const shapes = await activeSheet.Shapes;
    }

ActiveWorkbook.ActiveSheet.Visible

Use the Visible property to set whether the active worksheet is visible.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Visible

    Expression: document type, Application object

    A value of true for Visible makes the worksheet visible. A value of false hides the worksheet.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Hide the active worksheet.
      activeSheet.Visible = false;
    }

ActiveWorkbook.ActiveSheet.UsedRange

Use the UsedRange property to retrieve the used range in the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.UsedRange

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get the used range of the active worksheet.
      const usedRange = await activeSheet.UsedRange;
    }

ActiveWorkbook.ActiveSheet.Type

Use the Type property to retrieve the type of the active worksheet. Possible values: xlWorksheet (normal worksheet), xlEtDataBaseSheet (empty data sheet), or xlEtDashBoardSheet (dashboard).

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Type

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get the type of the active worksheet.
      const type = await activeSheet.Type;
      console.log(type);
    }

ActiveWorkbook.ActiveSheet.Id

Use the Id property to retrieve the ID of the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.Id

    Expression: document type, Application object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get the ID of the active worksheet.
      const id = await activeSheet.Id;
      console.log(id);
    }

ActiveWorkbook.ActiveSheet.ChartObjects

Use the ChartObjects property to return all charts in the active worksheet.

  • Syntax

    expression.ActiveWorkbook.ActiveSheet.ChartObjects

    Expression: document type, Application object

  • Example

    //@file=base.xlsx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the active worksheet in the active workbook.
      const activeSheet = await app.ActiveWorkbook.ActiveSheet;
    
      // Get all charts in the active worksheet.
      const chartObjects = await activeSheet.ChartObjects;
    }

    Returns the allowed edit ranges in the active worksheet of the active workbook.

    • Syntax

      expression.ActiveWorkbook.ActiveSheet.AllowEditRanges

      Expression: document type, Application object

    • Example

      async function example() {
        await instance.ready();
      
        const app = instance.Application;
      
        // Get the active worksheet in the active workbook.
        const activeSheet = await app.ActiveWorkbook.ActiveSheet;
      
        // Get the editable ranges of the active worksheet.
        const allowEditRanges = await activeSheet.AllowEditRanges;
      }