Excel.Application class

表示用于管理工作簿的 Excel 应用程序。Represents the Excel application that manages the workbook.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

Extends

属性

calculationEngineVersion

返回用于上次完整重新计算的 Excel 计算引擎版本。Returns the Excel calculation engine version used for the last full recalculation. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

calculationMode

返回工作簿中使用的计算模式, 如 CalculationMode 中的常量所定义。Returns the calculation mode used in the workbook, as defined by the constants in Excel.CalculationMode. 可能的值包括:AutomaticPossible values are: Automatic, Excel 控制重新计算的位置;AutomaticExceptTables, where Excel controls recalculation; AutomaticExceptTables, Excel 在其中控制重新计算, 但忽略表中的更改。Manual, where Excel controls recalculation but ignores changes in tables; Manual, 在用户请求计算时完成计算。, where calculation is done when the user requests it.

[API 集: ExcelApi 1.1 for get, 1.8 (用于设置)][ API set: ExcelApi 1.1 for get, 1.8 for set ]

calculationState

返回应用程序的计算状态。Returns the calculation state of the application. 有关详细信息,请参阅 Excel.CalculationState。See Excel.CalculationState for details. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

iterativeCalculation

返回“迭代计算”设置。Returns the Iterative Calculation settings. 在 Windows 和 Mac 上的 Excel 中, 这些设置将应用于 Excel 应用程序。In Excel on Windows and Mac, the settings will apply to the Excel Application. 在 Excel 中的 web 和其他平台上, 这些设置将应用于活动工作簿。In Excel on the web and other platforms, the settings will apply to the active workbook.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

方法

calculate(calculationType)

重新计算 Excel 中当前打开的所有工作簿。Recalculate all currently opened workbooks in Excel.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

calculate(calculationTypeString)

重新计算 Excel 中当前打开的所有工作簿。Recalculate all currently opened workbooks in Excel.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

load(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。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()

在下一次调用“context.sync()”前暂停计算。设置后,开发者负责重新计算工作簿,以确保传播所有依赖项。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 集: ExcelApi 1.6][ API set: ExcelApi 1.6 ]

suspendScreenUpdatingUntilNextSync()

在下一次调用“context.sync()”前暂停屏幕更新。Suspends sceen updating until the next "context.sync()" is called.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

toJSON()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始的 Excel 应用程序对象是 API 对象, 但toJSON方法返回一个简单的 JavaScript 对象 (类型为Excel.Interfaces.ApplicationData, 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.

属性详细信息

calculationEngineVersion

返回用于上次完整重新计算的 Excel 计算引擎版本。Returns the Excel calculation engine version used for the last full recalculation. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly calculationEngineVersion: number;

属性值

number

calculationMode

返回工作簿中使用的计算模式, 如 CalculationMode 中的常量所定义。Returns the calculation mode used in the workbook, as defined by the constants in Excel.CalculationMode. 可能的值包括:AutomaticPossible values are: Automatic, Excel 控制重新计算的位置;AutomaticExceptTables, where Excel controls recalculation; AutomaticExceptTables, Excel 在其中控制重新计算, 但忽略表中的更改。Manual, where Excel controls recalculation but ignores changes in tables; Manual, 在用户请求计算时完成计算。, where calculation is done when the user requests it.

[API 集: ExcelApi 1.1 for get, 1.8 (用于设置)][ API set: ExcelApi 1.1 for get, 1.8 for set ]

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

属性值

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

calculationState

返回应用程序的计算状态。Returns the calculation state of the application. 有关详细信息,请参阅 Excel.CalculationState。See Excel.CalculationState for details. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

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

属性值

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

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

context: RequestContext;

属性值

RequestContext

iterativeCalculation

返回“迭代计算”设置。Returns the Iterative Calculation settings. 在 Windows 和 Mac 上的 Excel 中, 这些设置将应用于 Excel 应用程序。In Excel on Windows and Mac, the settings will apply to the Excel Application. 在 Excel 中的 web 和其他平台上, 这些设置将应用于活动工作簿。In Excel on the web and other platforms, the settings will apply to the active workbook.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly iterativeCalculation: Excel.IterativeCalculation;

属性值

方法详细信息

calculate(calculationType)

重新计算 Excel 中当前打开的所有工作簿。Recalculate all currently opened workbooks in Excel.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

calculate(calculationType: Excel.CalculationType): void;

参数

calculationType
Excel.CalculationType

指定要使用的计算类型。Specifies the calculation type to use. 有关详细信息, 请参阅 CalculationType。See Excel.CalculationType for details.

返回

void

calculate(calculationTypeString)

重新计算 Excel 中当前打开的所有工作簿。Recalculate all currently opened workbooks in Excel.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

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

参数

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

指定要使用的计算类型。Specifies the calculation type to use. 有关详细信息, 请参阅 CalculationType。See Excel.CalculationType for details.

返回

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(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

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

参数

返回

注解

除了此签名之外, 此方法还具有以下签名:In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.Application-Where 选项是一个逗号分隔的字符串或一个字符串数组, 用于指定要加载的属性。load(option?: string | string[]): Excel.Application - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.Application-Where 选项。选择是一个用逗号分隔的字符串, 用于指定要加载的属性和选项。 expand 是一个用逗号分隔的字符串, 用于指定要加载的导航属性。load(option?: { select?: string; expand?: string; }): Excel.Application - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Application-仅适用于集合类型。load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Application - Only available on collection types. 它类似于前面的签名。It is similar to the preceding signature. Top 指定结果中可包含的集合项的最大数量。Option.top specifies the maximum number of collection items that can be included in the result. 选项。 skip 指定要跳过且不包含在结果中的项目数。Option.skip specifies the number of items that are to be skipped and not included in the result. 如果指定了 top 选项, 则在跳过指定数目的项目后将启动结果集。If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

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

参数

propertyNames
string | string[]

一个以逗号分隔的字符串或字符串数组, 用于指定要加载的属性。A comma-delimited string or an array of strings that specify the properties to load.

返回

示例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. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

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

参数

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

其中, propertyNamesAndPaths 是用逗号分隔的字符串, 用于指定要加载的属性和 propertyNamesAndPaths。扩展是一个用逗号分隔的字符串, 用于指定要加载的导航属性。Where 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.

返回

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。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;

参数

properties
Interfaces.ApplicationUpdateData

一个 JavaScript 对象, 其属性的结构 isomorphically 为在其上调用方法的对象的属性。A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

提供一个选项, 以在 properties 对象尝试设置任何只读属性时禁止显示错误。Provides an option to suppress errors if the properties object tries to set any read-only properties.

返回

void

注解

此方法具有以下附加签名: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;

参数

properties
Excel.Application

返回

void

suspendApiCalculationUntilNextSync()

在下一次调用“context.sync()”前暂停计算。设置后,开发者负责重新计算工作簿,以确保传播所有依赖项。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 集: ExcelApi 1.6][ API set: ExcelApi 1.6 ]

suspendApiCalculationUntilNextSync(): void;

返回

void

suspendScreenUpdatingUntilNextSync()

在下一次调用“context.sync()”前暂停屏幕更新。Suspends sceen updating until the next "context.sync()" is called.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

suspendScreenUpdatingUntilNextSync(): void;

返回

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()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始的 Excel 应用程序对象是 API 对象, 但toJSON方法返回一个简单的 JavaScript 对象 (类型为Excel.Interfaces.ApplicationData, 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;

返回