This topic describes how to obtain the workbook object and workbook name, and add worksheets in a table file.
Active workbook object
Obtain a workbook object that represents the active workbook.
Syntax
Expression.ActiveWorkbookExpressions: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Active workbook. const activeWorkbook = await app.ActiveWorkbook; }
Active workbook name
Obtain a collection of workbook names.
Syntax
Expression.ActiveWorkbook.NamesExpressions: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Active workbook. const activeWorkbook = await app.ActiveWorkbook; // A collection of workbook names. const names = await activeWorkbook.Names; }
Worksheet
Obtain a worksheet object
Syntax
Expression.ActiveWorkbook.SheetsExpressions: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // The worksheet object. const sheets = await app.ActiveWorkbook.Sheets; }
Add worksheets
Syntax
Expression.ActiveWorkbook.Sheets.Add({ Before, After, Count, Type, Name })Expressions: the document type application object.
Parameters
Attribute
Data type
Required
Description
Before
String/Number
Yes
Specifies the object of the worksheet before which the new worksheet is added.
After
String/Number
No
Specifies the object of the worksheet after which the new worksheet is added.
Count
Number
No
Specifies the number of worksheets to add. The default value is the number of selected sheets.
Type
Enum
No
Specifies the worksheet type. Valid values of
Enum.XlSheetType:-4167 or xlWorksheet: worksheet.
-4116 or xlDialogSheet: dialog sheet.
-4109 or xlChart: chart.
3 or xlExcel4MacroSheet: Excel version 4 macro sheet.
4 or xlExcel4IntlMacroSheet: Excel version 4 international macro sheet.
Name
Name
No
Specifies the worksheet name.
Example
async function example() { await instance.ready(); const app = instance.Application; // The worksheet object. const sheets = await app.ActiveWorkbook.Sheets; // Add a worksheet. await sheets.Add(null, null, 1, app.Enum.XlSheetType.xlWorksheet, 'new worksheet'); }
Obtain the number of worksheets
Syntax
Expression.ActiveWorkbook.Sheets.CountExpressions: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // The worksheet object. const sheets = await app.ActiveWorkbook.Sheets; // The number of worksheets. const count = await sheets.Count; console.log(count); }
Obtain the worksheet type
Syntax
Expression.ActiveWorkbook.Sheets.Item(Index).TypeExpressions: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // The worksheet object. const sheetIndex = 2; // The sequence number of the worksheet. The number starts from 1. const sheet = await app.ActiveWorkbook.Sheets.Item(sheetIndex) // The worksheet type. const Type = await sheet.Type; console.log(Type); }
Obtain a single worksheet object
Obtain an active sheet in an active workbook.
Currently, a worksheet object can be used in the same way as an active sheet.
Syntax
Expression.ActiveWorkbook.Sheets.Item(Index)Expressions: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // The active sheet in the active workbook. const activeSheet = await app.ActiveWorkbook.Sheets.Item(1); }
Enable or disable multi-person synchronous filtering
Syntax
Expression.ActiveWorkbook.SetFilterShared({ Checked })Expressions: the document type application object.
Parameter
Attribute
Data type
Required
Description
Checked
Boolean
Yes
Enable or disable multi-person synchronous filtering.
true
false
Example
async function example() { await instance.ready(); const app = instance.Application; // Active workbook. const activeWorkbook = await app.ActiveWorkbook; // Enable multi-person synchronous filtering. const result = await activeWorkbook.SetFilterShared(true); }