Provides methods to manage the active worksheet in a table document, including retrieving editable ranges, protecting and unprotecting sheets, and controlling worksheet visibility.
In all syntax references, Expression represents the document type application object.
Get the active worksheet object
Retrieves the active worksheet from the active workbook.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet -
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; }
Editable ranges
Manage editable ranges on the active worksheet: retrieve, add, delete, and configure user access.
Get the editable range objects
Retrieves all editable ranges on the active worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges -
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 range objects. const allowEditRanges = await activeSheet.AllowEditRanges; }
Add an editable range
Adds an editable range to a protected worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Add({ Title, Range, Password }) -
Parameters
Parameter
Data type
Required
Description
Range
Object
Yes
The range object that defines the editable area.
Title
String
No
The title of the editable range.
Password
String
No
The password for the editable range.
-
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. const allowEditRanges = await activeSheet.AllowEditRanges; // Set the range from A1 to E20. const range = await activeSheet.Range('$A1:$E20'); // Add an editable range. await allowEditRanges.Add(undefined, range, 'WebOffice'); }
Get the number of editable ranges
Retrieves the number of editable ranges on a protected worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Count -
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. const allowEditRanges = await activeSheet.AllowEditRanges; // Get the number of editable ranges. const count = await allowEditRanges.Count; }
Manage individual editable ranges
The AllowEditRanges collection provides methods to work with individual editable ranges on a protected worksheet.
Get an editable range
Retrieves an editable range by its index.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Item(Index) -
Parameters
Parameter
Data type
Required
Description
Index
Variant
Yes
The index of the editable range 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 an editable range by index. const allowEditRanges = await activeSheet.AllowEditRanges; const item = await allowEditRanges.Item(1); }
Delete an editable range
Deletes an editable range from a protected worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Item(Index).Delete() -
Parameters
Parameter
Data type
Required
Description
Password
Variant
Yes
The password for the protected 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; // Delete an editable range. const allowEditRanges = await activeSheet.AllowEditRanges; const item = await allowEditRanges.Item(1); await item.Delete('123'); }
Get the range of an editable range
Retrieves the cell range defined by an individual editable range on a protected worksheet.
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Item(Index).Range
-
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 selectable range of an editable range. const allowEditRanges = await activeSheet.AllowEditRanges; const item = await allowEditRanges.Item(1); await item.Range; }
Get the user group of an editable range
Retrieves the user group associated with an editable range on a protected worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Item(Index).Users -
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 an editable range. const allowEditRanges = await activeSheet.AllowEditRanges; const item = await allowEditRanges.Item(1); // Get the user group of the editable range. await item.Users; }
Add a user to an editable range
Adds a user to an editable range on a protected worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Item(Index).AddUser() Parameters
|
Parameter |
Data type |
Required |
Description |
|
Password |
Variant |
Yes |
The password for the protected worksheet. |
|
UserId |
Variant |
Yes |
The ID of the user to add. |
-
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 an editable range. const allowEditRanges = await activeSheet.AllowEditRanges; const item = await allowEditRanges.Item(1); // Add a user to the editable range. await item.AddUser({Password:'', UserId:'280289376'}); }
Remove a user from an editable range
Removes a user from an editable range on a protected worksheet.
Syntax
Expression.ActiveWorkbook.ActiveSheet.AllowEditRanges.Item(Index).RemoveUser()
Parameters
|
Parameter |
Data type |
Required |
Description |
|
Password |
Variant |
Yes |
The password for the protected worksheet. |
|
UserId |
Variant |
Yes |
The ID of the user to remove. |
-
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 an editable range. const allowEditRanges = await activeSheet.AllowEditRanges; const item = await allowEditRanges.Item(1); // Remove a user from the editable range. await item.RemoveUser({Password:'', UserId:'280289376'}); }
Get the chart objects
Retrieves all chart objects on the active worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.ChartObjects -
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 chart objects on the worksheet. const chartObjects = await activeSheet.ChartObjects; }
Get rows
Retrieves a range object that represents all rows on the worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Rows -
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 on the worksheet. const rows = await activeSheet.Rows; }
Get columns
Retrieves a range object that represents all columns on the worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Columns -
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 on the worksheet. const columns = await activeSheet.Columns; }
Get cells
Retrieves a range object that represents all cells on the worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Cells -
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 on the worksheet. const cells = await activeSheet.Cells; }
Delete a worksheet
Deletes the active worksheet from the active workbook.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Delete() -
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 worksheet. await activeSheet.Delete(); }
Get the worksheet index
Retrieves the index of the active worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Index -
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 of the worksheet. const index = await activeSheet.Index; console.log(index); }
Get the names on a worksheet
Retrieves the collection of all named ranges defined on the worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Names -
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 named ranges defined on the worksheet. const names = await activeSheet.Names; }
Protect a worksheet
Protects the active worksheet to prevent unauthorized modifications. All Allow* parameters default to false unless noted otherwise.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Protect({ Password, DrawingObjects, Scenarios, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables }) -
Parameters
Parameter
Data type
Required
Default
Description
Password
String
No
None
The password for the worksheet or workbook. The password is case-sensitive.
-
If omitted, the worksheet or workbook can be unprotected without a password.
-
If specified, the password is required to unprotect the worksheet or workbook.
ImportantStore your passwords in a safe place. If you forget the password, you cannot unprotect the worksheet or workbook.
DrawingObjects
Boolean
No
false
Specifies whether to protect the shapes.
Scenarios
Boolean
No
true
Specifies whether to protect worksheet scenarios. Valid only for worksheets.
AllowFormattingCells
Boolean
No
false
Specifies whether to allow users to format cells on the protected worksheet.
AllowFormattingColumns
Boolean
No
false
Specifies whether to allow users to format columns on the protected worksheet.
AllowFormattingRows
Boolean
No
false
Specifies whether to allow users to format rows on the protected worksheet.
AllowInsertingColumns
Boolean
No
false
Specifies whether to allow users to insert columns on the protected worksheet.
AllowInsertingRows
Boolean
No
false
Specifies whether to allow users to insert rows on the protected worksheet.
AllowInsertingHyperlinks
Boolean
No
false
Specifies whether to allow users to insert hyperlinks on the protected worksheet.
AllowDeletingColumns
Boolean
No
false
Specifies whether to allow users to delete columns on the protected worksheet. If set to
true, each cell in the column must be unlocked before the column can be deleted.AllowDeletingRows
Boolean
No
false
Specifies whether to allow users to delete rows on the protected worksheet. If set to
true, each cell in the row must be unlocked before the row can be deleted.AllowSorting
Boolean
No
false
Specifies whether to allow users to sort on the protected worksheet. If set to
true, each cell in the sort range must be unlocked or unprotected.AllowFiltering
Boolean
No
false
Specifies whether to allow users to set filters on the protected worksheet. If set to
true, users can change the filter criteria or set filters on an existing auto filter, but cannot enable or disable auto filters.AllowUsingPivotTables
Boolean
No
false
Specifies whether to allow users to use pivot table reports on the protected 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; // Protect the worksheet with a password. activeSheet.Protect('123456'); }
Remove protection from a worksheet or workbook
Removes protection from a worksheet or workbook. This method has no effect if the worksheet or workbook is not protected.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Unprotect({ Password }) -
Parameters
Parameter
Data type
Required
Description
Password
String
No
The password for the protection. Specify the password only if the worksheet or workbook was protected with one.
-
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 protection from the worksheet. activeSheet.Unprotect('123456'); }
Get the shape objects
Retrieves all shape objects on the active worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Shapes -
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 on the worksheet. const shapes = await activeSheet.Shapes; }
Set worksheet visibility
Shows or hides the active worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Visible -
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 worksheet. activeSheet.Visible = false; }
Get the used range
Retrieves a range object that represents the used range on the worksheet.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.UsedRange -
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 on the worksheet. const usedRange = await activeSheet.UsedRange; }
Get a range object
Retrieves a range object that represents a cell or a range of cells.
-
Syntax
Expression.ActiveWorkbook.ActiveSheet.Range -
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 range object representing a cell or range of cells. const range = await activeSheet.Range; }