Excel.Application class

Represents the Excel application that manages the workbook.

[ API set: ExcelApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

calculationEngineVersion

Returns the Excel calculation engine version used for the last full recalculation. Read-only.

[ API set: ExcelApi 1.9 ]

calculationMode

Returns the calculation mode used in the workbook, as defined by the constants in Excel.CalculationMode. Possible values are: Automatic, where Excel controls recalculation; AutomaticExceptTables, where Excel controls recalculation but ignores changes in tables; Manual, where calculation is done when the user requests it.

[ API set: ExcelApi 1.1 for get, 1.8 for set ]

calculationState

Returns the calculation state of the application. See Excel.CalculationState for details. Read-only.

[ API set: ExcelApi 1.9 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

iterativeCalculation

Returns the Iterative Calculation settings. In Excel on Windows and Mac, the settings will apply to the Excel Application. In Excel on the web and other platforms, the settings will apply to the active workbook.

[ API set: ExcelApi 1.9 ]

Methods

calculate(calculationType)

Recalculate all currently opened workbooks in Excel.

[ API set: ExcelApi 1.1 ]

calculate(calculationTypeString)

Recalculate all currently opened workbooks in Excel.

[ API set: ExcelApi 1.1 ]

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

suspendApiCalculationUntilNextSync()

Suspends calculation until the next "context.sync()" is called. Once set, it is the developer's responsibility to re-calc the workbook, to ensure that any dependencies are propagated.

[ API set: ExcelApi 1.6 ]

suspendScreenUpdatingUntilNextSync()

Suspends sceen updating until the next "context.sync()" is called.

[ API set: ExcelApi 1.9 ]

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Application object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ApplicationData) that contains shallow copies of any loaded child properties from the original object.

Property Details

calculationEngineVersion

Returns the Excel calculation engine version used for the last full recalculation. Read-only.

[ API set: ExcelApi 1.9 ]

readonly calculationEngineVersion: number;

Property Value

number

calculationMode

Returns the calculation mode used in the workbook, as defined by the constants in Excel.CalculationMode. Possible values are: Automatic, where Excel controls recalculation; AutomaticExceptTables, where Excel controls recalculation but ignores changes in tables; Manual, where calculation is done when the user requests it.

[ API set: ExcelApi 1.1 for get, 1.8 for set ]

calculationMode: Excel.CalculationMode | "Automatic" | "AutomaticExceptTables" | "Manual";

Property Value

Excel.CalculationMode | "Automatic" | "AutomaticExceptTables" | "Manual"

calculationState

Returns the calculation state of the application. See Excel.CalculationState for details. Read-only.

[ API set: ExcelApi 1.9 ]

readonly calculationState: Excel.CalculationState | "Done" | "Calculating" | "Pending";

Property Value

Excel.CalculationState | "Done" | "Calculating" | "Pending"

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

iterativeCalculation

Returns the Iterative Calculation settings. In Excel on Windows and Mac, the settings will apply to the Excel Application. In Excel on the web and other platforms, the settings will apply to the active workbook.

[ API set: ExcelApi 1.9 ]

readonly iterativeCalculation: Excel.IterativeCalculation;

Property Value

Method Details

calculate(calculationType)

Recalculate all currently opened workbooks in Excel.

[ API set: ExcelApi 1.1 ]

calculate(calculationType: Excel.CalculationType): void;

Parameters

calculationType
Excel.CalculationType

Specifies the calculation type to use. See Excel.CalculationType for details.

Returns

void

calculate(calculationTypeString)

Recalculate all currently opened workbooks in Excel.

[ API set: ExcelApi 1.1 ]

calculate(calculationTypeString: "Recalculate" | "Full" | "FullRebuild"): void;

Parameters

calculationTypeString
"Recalculate" | "Full" | "FullRebuild"

Specifies the calculation type to use. See Excel.CalculationType for details.

Returns

void

Examples

Excel.run(function (ctx) {
    ctx.workbook.application.calculate('Full');
    return ctx.sync();
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: Excel.Interfaces.ApplicationLoadOptions): Excel.Application;

Parameters

options
Excel.Interfaces.ApplicationLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.Application;

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

Examples

Excel.run(function (ctx) {
    var application = ctx.workbook.application;
    application.load('calculationMode');
    return ctx.sync().then(function() {
        console.log(application.calculationMode);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.Application;

Parameters

propertyNamesAndPaths
{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.ApplicationUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
Interfaces.ApplicationUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

Remarks

This method has the following additional signature:

set(properties: Excel.Application): void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.Application): void;

Parameters

properties
Excel.Application

Returns

void

suspendApiCalculationUntilNextSync()

Suspends calculation until the next "context.sync()" is called. Once set, it is the developer's responsibility to re-calc the workbook, to ensure that any dependencies are propagated.

[ API set: ExcelApi 1.6 ]

suspendApiCalculationUntilNextSync(): void;

Returns

void

suspendScreenUpdatingUntilNextSync()

Suspends sceen updating until the next "context.sync()" is called.

[ API set: ExcelApi 1.9 ]

suspendScreenUpdatingUntilNextSync(): void;

Returns

void

Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();
    const rowCount = 500;
    const columnCount = 20;

    const startTime = Date.now();
    console.log("Starting...");

    if (pauseScreenPainting) {
        context.application.suspendScreenUpdatingUntilNextSync();
    }

    for (let i = 0; i < rowCount; i++) {
        for (let j = 0; j < columnCount; j++) {
            let cell = sheet.getCell(i, j);
            cell.values = [[i * j * Math.random()]];
            if (untrack) {
                cell.untrack();
            }
        }
    }

    await context.sync();

    console.log(`Ending. Adding ${rowCount * columnCount} cells took ${Date.now() - startTime} milliseconds`);
});

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Application object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.ApplicationData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.ApplicationData;

Returns