Excel.Application class
Represents the Excel application that manages the workbook.
- Extends
Remarks
Properties
calculation |
Returns the Excel calculation engine version used for the last full recalculation. |
calculation |
Returns the calculation mode used in the workbook, as defined by the constants in |
calculation |
Returns the calculation state of the application. See |
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
iterative |
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. |
Methods
calculate(calculation |
Recalculate all currently opened workbooks in Excel. |
calculate(calculation |
Recalculate all currently opened workbooks in Excel. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
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. |
suspend |
Suspends calculation until the next |
suspend |
Suspends screen updating until the next Note*: Don't call |
toJSON() | Overrides the JavaScript |
Property Details
calculationEngineVersion
Returns the Excel calculation engine version used for the last full recalculation.
readonly calculationEngineVersion: number;
Property Value
number
Remarks
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.
calculationMode: Excel.CalculationMode | "Automatic" | "AutomaticExceptTables" | "Manual";
Property Value
Excel.CalculationMode | "Automatic" | "AutomaticExceptTables" | "Manual"
Remarks
calculationState
Returns the calculation state of the application. See Excel.CalculationState
for details.
readonly calculationState: Excel.CalculationState | "Done" | "Calculating" | "Pending";
Property Value
Excel.CalculationState | "Done" | "Calculating" | "Pending"
Remarks
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.
readonly iterativeCalculation: Excel.IterativeCalculation;
Property Value
Remarks
Method Details
calculate(calculationType)
Recalculate all currently opened workbooks in Excel.
calculate(calculationType: Excel.CalculationType): void;
Parameters
- calculationType
- Excel.CalculationType
Specifies the calculation type to use. See Excel.CalculationType
for details.
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/90-scenarios/performance-optimization.yaml
await Excel.run(async (context) => {
context.application.calculate(Excel.CalculationType.full);
});
calculate(calculationTypeString)
Recalculate all currently opened workbooks in Excel.
calculate(calculationTypeString: "Recalculate" | "Full" | "FullRebuild"): void;
Parameters
- calculationTypeString
-
"Recalculate" | "Full" | "FullRebuild"
Specifies the calculation type to use. See Excel.CalculationType
for details.
Returns
void
Remarks
Examples
await Excel.run(async (context) => {
context.workbook.application.calculate('Full');
await context.sync();
});
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
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
await Excel.run(async (context) => {
const application = context.workbook.application;
application.load('calculationMode');
await context.sync();
console.log(application.calculationMode);
});
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
- Excel.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
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.
suspendApiCalculationUntilNextSync(): void;
Returns
void
Remarks
suspendScreenUpdatingUntilNextSync()
Suspends screen updating until the next context.sync()
is called.
Note*: Don't call suspendScreenUpdatingUntilNextSync
repeatedly (such as in a loop). Repeated calls will cause the Excel window to flicker.
suspendScreenUpdatingUntilNextSync(): void;
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/90-scenarios/performance-optimization.yaml
await Excel.run(async (context) => {
// Recreate the data in the worksheet with random data.
const sheet = context.workbook.worksheets.getActiveWorksheet();
const startTime = Date.now();
console.log("Starting...");
// If other parts of the sample have toggled screen painting off, this will stop screen updating until context.sync is called.
if (pauseScreenPainting) {
context.application.suspendScreenUpdatingUntilNextSync();
}
for (let i = 1; i < ROW_COUNT; i++) {
for (let j = 1; j < COLUMN_COUNT; j++) {
let cell = sheet.getCell(i, j);
cell.values = [[i * j * Math.random()]];
// If other parts of the sample have toggled tracking off, we will avoid tracking this range and having to manage the proxy objects.
// For more information, see https://learn.microsoft.com/office/dev/add-ins/concepts/resource-limits-and-performance-optimization#untrack-unneeded-proxy-objects
if (untrack) {
cell.untrack();
}
}
}
await context.sync();
console.log(`Ending. Adding ${ROW_COUNT * COLUMN_COUNT} 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
Office Add-ins