Excel.Application class

Represents the Excel application that manages the workbook.

Extends

Remarks

[ API set: ExcelApi 1.1 ]

Properties

calculationEngineVersion

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

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.

calculationState

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

context

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

cultureInfo

Provides information based on current system culture settings. This includes the culture names, number formatting, and other culturally dependent settings.

decimalSeparator

Gets the string used as the decimal separator for numeric values. This is based on the local Excel settings.

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.

thousandsSeparator

Gets the string used to separate groups of digits to the left of the decimal for numeric values. This is based on the local Excel settings.

useSystemSeparators

Specifies if the system separators of Excel are enabled. System separators include the decimal separator and thousands separator.

Methods

calculate(calculationType)

Recalculate all currently opened workbooks in Excel.

calculate(calculationTypeString)

Recalculate all currently opened workbooks in Excel.

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.

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.

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.

readonly calculationEngineVersion: number;

Property Value

number

Remarks

[ 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.

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

Property Value

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

Remarks

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

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

[ 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.

context: RequestContext;

Property Value

cultureInfo

Provides information based on current system culture settings. This includes the culture names, number formatting, and other culturally dependent settings.

readonly cultureInfo: Excel.CultureInfo;

Property Value

Remarks

[ API set: ExcelApi 1.11 ]

decimalSeparator

Gets the string used as the decimal separator for numeric values. This is based on the local Excel settings.

readonly decimalSeparator: string;

Property Value

string

Remarks

[ API set: ExcelApi 1.11 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/50-workbook/culture-info.yaml

await Excel.run(async (context) => {
  context.application.load("decimalSeparator,thousandsSeparator");
  context.application.cultureInfo.numberFormat.load("numberDecimalSeparator,numberGroupSeparator");
  await context.sync();

  // Local settings are set under the "Options > Advanced" menu.
  const localDecimalSeparator = context.application.decimalSeparator;
  const localThousandsSeparator = context.application.thousandsSeparator;

  const systemDecimalSeparator = context.application.cultureInfo.numberFormat.numberDecimalSeparator;
  const systemThousandsSeparator = context.application.cultureInfo.numberFormat.numberGroupSeparator;

  console.log("Local character settings: ");
  console.log(`  Local decimal separator: ${localDecimalSeparator}`);
  console.log(`  Local thousands separator: ${localThousandsSeparator}`);

  console.log("System culture settings: ");
  console.log(`  System decimal separator: ${systemDecimalSeparator}`);
  console.log(`  System thousands separator: ${systemThousandsSeparator}`);
  console.log(`  `);

  await context.sync();
});

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

[ API set: ExcelApi 1.9 ]

thousandsSeparator

Gets the string used to separate groups of digits to the left of the decimal for numeric values. This is based on the local Excel settings.

readonly thousandsSeparator: string;

Property Value

string

Remarks

[ API set: ExcelApi 1.11 ]

useSystemSeparators

Specifies if the system separators of Excel are enabled. System separators include the decimal separator and thousands separator.

readonly useSystemSeparators: boolean;

Property Value

boolean

Remarks

[ API set: ExcelApi 1.11 ]

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

[ API set: ExcelApi 1.1 ]

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

[ API set: ExcelApi 1.1 ]

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

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

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

[ API set: ExcelApi 1.6 ]

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

[ API set: ExcelApi 1.9 ]

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