Excel.Workbook class

工作簿是顶级对象,它包含相关 workbook 对象,例如工作表、表、范围等。Workbook is the top level object which contains related workbook objects such as worksheets, tables, ranges, etc.

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

Extends

属性

application

表示包含此工作簿的 Excel 应用程序实例。Represents the Excel application instance that contains this workbook. 只读。Read-only.

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

autoSave

指定工作簿是否处于自动保存模式。Specifies whether or not the workbook is in autosave mode. 只读。Read-Only.

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

bindings

表示属于工作簿的绑定的集合。Represents a collection of bindings that are part of the workbook. 只读。Read-only.

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

calculationEngineVersion

返回有关 Excel 计算引擎的版本号。Returns a number about the version of Excel Calculation Engine. 只读。Read-Only.

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

chartDataPointTrack

如果工作簿中的所有图表都跟踪它们所附加的实际数据点,则为 True。True if all charts in the workbook are tracking the actual data points to which they are attached. 假如果图表跟踪数据点的索引。False if the charts track the index of the data points.

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

comments

表示与工作簿关联的批注集合。Represents a collection of Comments associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

context

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

customXmlParts

表示此工作簿包含的自定义 XML 部件的集合。Represents the collection of custom XML parts contained by this workbook. 只读。Read-only.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

dataConnections

表示工作簿中的所有数据连接。Represents all data connections in the workbook. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

functions

代表可用于计算的工作表函数的集合。Represents a collection of worksheet functions that can be used for computation. 只读。Read-only.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

isDirty

指定自上次保存以来是否对指定的工作簿进行任何更改。Specifies whether or not changes have been made since the workbook was last saved. 如果要关闭修改过的工作簿而不保存或提示保存它, 则可以将该属性设置为 true。You can set this property to true if you want to close a modified workbook without either saving it or being prompted to save it.

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

name

获取工作簿名称。Gets the workbook name. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

names

表示工作簿范围内的已命名项目(称为区域和常量)的集合。Represents a collection of workbook scoped named items (named ranges and constants). 只读。Read-only.

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

pivotTables

表示一组与 workbook 相关联的 PivotTable 对象。Represents a collection of PivotTables associated with the workbook. 只读。Read-only.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

pivotTableStyles

表示一组与工作簿相关联的 PivotTableStyles。Represents a collection of PivotTableStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

previouslySaved

指定工作簿是否已在本地或在线保存。Specifies whether or not the workbook has ever been saved locally or online. 只读。Read-Only.

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

properties

获取工作簿属性。Gets the workbook properties. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

protection

返回工作簿的工作簿保护对象。Returns workbook protection object for a workbook. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readOnly

如果在只读模式下打开工作簿,则为 True。True if the workbook is open in Read-only mode. 只读。Read-only.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

settings

表示一组与 workbook 相关联的 setting 对象。Represents a collection of Settings associated with the workbook. 只读。Read-only.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

slicers

表示与工作簿关联的切片器集合。Represents a collection of Slicers associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

slicerStyles

表示一组与工作簿相关联的 SlicerStyles。Represents a collection of SlicerStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

styles

表示与工作簿关联的样式的集合。Represents a collection of styles associated with the workbook. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

tables

表示与工作簿关联的表的集合。Represents a collection of tables associated with the workbook. 只读。Read-only.

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

tableStyles

表示一组与工作簿相关联的 TableStyles。Represents a collection of TableStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

timelineStyles

表示一组与工作簿相关联的 TimelineStyles。Represents a collection of TimelineStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

use1904DateSystem

如果工作簿使用 1904 日期系统,则为 True。True if the workbook uses the 1904 date system.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

usePrecisionAsDisplayed

如果此工作簿中的计算仅使用显示的数字精度来完成,则为 True。True if calculations in this workbook will be done using only the precision of the numbers as they're displayed. 将此属性从 false 切换到 true 时, 数据将永久丢失精度。Data will permanently lose accuracy when switching this property from false to true.

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

worksheets

表示与工作簿关联的工作表的集合。Represents a collection of worksheets associated with the workbook. 只读。Read-only.

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

方法

close(closeBehavior)

关闭当前工作簿。Close current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

close(closeBehaviorString)

关闭当前工作簿。Close current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

getActiveCell()

获取工作簿中当前处于活动状态的单元格。Gets the currently active cell from the workbook.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

getActiveChart()

获取工作簿中的当前活动图表。Gets the currently active chart in the workbook. 如果没有活动图表, 则会引发ItemNotFound异常。If there is no active chart, an ItemNotFound exception is thrown.

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

getActiveChartOrNullObject()

获取工作簿中的当前活动图表。Gets the currently active chart in the workbook. 如果没有活动图表, 则返回 null 对象。If there is no active chart, a null object is returned.

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

getActiveSlicer()

获取工作簿中当前处于活动状态的切片器。Gets the currently active slicer in the workbook. 如果没有活动切片器, 则会ItemNotFound引发异常。If there is no active slicer, an ItemNotFound exception is thrown.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

getActiveSlicerOrNullObject()

获取工作簿中当前处于活动状态的切片器。Gets the currently active slicer in the workbook. 如果没有处于活动状态的切片器,则返回 null 对象。If there is no active slicer, a null object is returned.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

getIsActiveCollabSession()

如果多个用户正在编辑工作簿(共同创作),则为 True。True if the workbook is being edited by multiple users (co-authoring). 请注意, 当工作簿状态发生变化以及更改在方法结果上反映时, 可能会有一些延迟。Please be aware there might be some delay between when the workbook status changes and when the changes are reflected on the result of the method.

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

getSelectedRange()

从工作簿中获取当前选定的单个区域。Gets the currently selected single range from the workbook. 如果选择了多个区域, 则此方法将引发错误。If there are multiple ranges selected, this method will throw an error.

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

getSelectedRanges()

从工作簿中获取当前选定的一个或多个区域。Gets the currently selected one or more ranges from the workbook. 与 getSelectedRange() 不同,此方法返回表示所有选定区域的 RangeAreas 对象。Unlike getSelectedRange(), this method returns a RangeAreas object that represents all the selected ranges.

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

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.

save(saveBehavior)

保存当前工作簿。Save current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

save(saveBehaviorString)

保存当前工作簿。Save current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

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.

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.WorkbookData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Workbook object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.WorkbookData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

事件

onAutoSaveSettingChanged

在工作簿上更改“自动保存”设置时发生。Occurs when the autoSave setting is changed on the workbook.

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

onSelectionChanged

文档中的选择更改时发生。Occurs when the selection in the document is changed.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

属性详细信息

application

表示包含此工作簿的 Excel 应用程序实例。Represents the Excel application instance that contains this workbook. 只读。Read-only.

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

readonly application: Excel.Application;

属性值

autoSave

指定工作簿是否处于自动保存模式。Specifies whether or not the workbook is in autosave mode. 只读。Read-Only.

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

readonly autoSave: boolean;

属性值

boolean

bindings

表示属于工作簿的绑定的集合。Represents a collection of bindings that are part of the workbook. 只读。Read-only.

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

readonly bindings: Excel.BindingCollection;

属性值

calculationEngineVersion

返回有关 Excel 计算引擎的版本号。Returns a number about the version of Excel Calculation Engine. 只读。Read-Only.

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

readonly calculationEngineVersion: number;

属性值

number

chartDataPointTrack

如果工作簿中的所有图表都跟踪它们所附加的实际数据点,则为 True。True if all charts in the workbook are tracking the actual data points to which they are attached. 假如果图表跟踪数据点的索引。False if the charts track the index of the data points.

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

chartDataPointTrack: boolean;

属性值

boolean

comments

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

表示与工作簿关联的批注集合。Represents a collection of Comments associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly comments: Excel.CommentCollection;

属性值

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

customXmlParts

表示此工作簿包含的自定义 XML 部件的集合。Represents the collection of custom XML parts contained by this workbook. 只读。Read-only.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

readonly customXmlParts: Excel.CustomXmlPartCollection;

属性值

dataConnections

表示工作簿中的所有数据连接。Represents all data connections in the workbook. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly dataConnections: Excel.DataConnectionCollection;

属性值

functions

代表可用于计算的工作表函数的集合。Represents a collection of worksheet functions that can be used for computation. 只读。Read-only.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

readonly functions: Excel.Functions;

属性值

isDirty

指定自上次保存以来是否对指定的工作簿进行任何更改。Specifies whether or not changes have been made since the workbook was last saved. 如果要关闭修改过的工作簿而不保存或提示保存它, 则可以将该属性设置为 true。You can set this property to true if you want to close a modified workbook without either saving it or being prompted to save it.

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

isDirty: boolean;

属性值

boolean

name

获取工作簿名称。Gets the workbook name. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly name: string;

属性值

string

names

表示工作簿范围内的已命名项目(称为区域和常量)的集合。Represents a collection of workbook scoped named items (named ranges and constants). 只读。Read-only.

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

readonly names: Excel.NamedItemCollection;

属性值

pivotTables

表示一组与 workbook 相关联的 PivotTable 对象。Represents a collection of PivotTables associated with the workbook. 只读。Read-only.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

readonly pivotTables: Excel.PivotTableCollection;

属性值

pivotTableStyles

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

表示一组与工作簿相关联的 PivotTableStyles。Represents a collection of PivotTableStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly pivotTableStyles: Excel.PivotTableStyleCollection;

属性值

previouslySaved

指定工作簿是否已在本地或在线保存。Specifies whether or not the workbook has ever been saved locally or online. 只读。Read-Only.

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

readonly previouslySaved: boolean;

属性值

boolean

properties

获取工作簿属性。Gets the workbook properties. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly properties: Excel.DocumentProperties;

属性值

示例Examples

await Excel.run(async (context) => {
    let titleValue = "Excel document properties API";
    let subjectValue = "Set and get document properties";
    let keywordsValue = "Set and get operations";
    let commentsValue = "This is an Excel document properties API code sample";
    let categoryValue = "Office Add-ins";
    let managerValue = "John";
    let companyValue = "Microsoft";

    let docProperties = context.workbook.properties;

    // Set the writeable document properties.
    docProperties.title = titleValue;
    docProperties.subject = subjectValue;
    docProperties.keywords = keywordsValue;
    docProperties.comments = commentsValue;
    docProperties.category = categoryValue;
    docProperties.manager = managerValue;
    docProperties.company = companyValue;

    await context.sync();

    console.log("Set the following document properties: title, subject, keywords, comments, category, manager, company.");
});

protection

返回工作簿的工作簿保护对象。Returns workbook protection object for a workbook. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly protection: Excel.WorkbookProtection;

属性值

readOnly

如果在只读模式下打开工作簿,则为 True。True if the workbook is open in Read-only mode. 只读。Read-only.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

readonly readOnly: boolean;

属性值

boolean

settings

表示一组与 workbook 相关联的 setting 对象。Represents a collection of Settings associated with the workbook. 只读。Read-only.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

readonly settings: Excel.SettingCollection;

属性值

slicers

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

表示与工作簿关联的切片器集合。Represents a collection of Slicers associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly slicers: Excel.SlicerCollection;

属性值

slicerStyles

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

表示一组与工作簿相关联的 SlicerStyles。Represents a collection of SlicerStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly slicerStyles: Excel.SlicerStyleCollection;

属性值

styles

表示与工作簿关联的样式的集合。Represents a collection of styles associated with the workbook. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly styles: Excel.StyleCollection;

属性值

tables

表示与工作簿关联的表的集合。Represents a collection of tables associated with the workbook. 只读。Read-only.

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

readonly tables: Excel.TableCollection;

属性值

tableStyles

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

表示一组与工作簿相关联的 TableStyles。Represents a collection of TableStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly tableStyles: Excel.TableStyleCollection;

属性值

timelineStyles

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

表示一组与工作簿相关联的 TimelineStyles。Represents a collection of TimelineStyles associated with the workbook. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly timelineStyles: Excel.TimelineStyleCollection;

属性值

use1904DateSystem

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

如果工作簿使用 1904 日期系统,则为 True。True if the workbook uses the 1904 date system.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

use1904DateSystem: boolean;

属性值

boolean

usePrecisionAsDisplayed

如果此工作簿中的计算仅使用显示的数字精度来完成,则为 True。True if calculations in this workbook will be done using only the precision of the numbers as they're displayed. 将此属性从 false 切换到 true 时, 数据将永久丢失精度。Data will permanently lose accuracy when switching this property from false to true.

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

usePrecisionAsDisplayed: boolean;

属性值

boolean

worksheets

表示与工作簿关联的工作表的集合。Represents a collection of worksheets associated with the workbook. 只读。Read-only.

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

readonly worksheets: Excel.WorksheetCollection;

属性值

方法详细信息

close(closeBehavior)

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

关闭当前工作簿。Close current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

close(closeBehavior?: Excel.CloseBehavior): void;

参数

closeBehavior
Excel.CloseBehavior

工作簿关闭行为。workbook close behavior.

返回

void

示例Examples

await Excel.run(async (context) => {
    context.workbook.close(Excel.CloseBehavior.save);
});

close(closeBehaviorString)

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

关闭当前工作簿。Close current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

close(closeBehaviorString?: "Save" | "SkipSave"): void;

参数

closeBehaviorString
"Save" | "SkipSave"

工作簿关闭行为。workbook close behavior.

返回

void

getActiveCell()

获取工作簿中当前处于活动状态的单元格。Gets the currently active cell from the workbook.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

getActiveCell(): Excel.Range;

返回

示例Examples

await Excel.run(async (context) => {

    let myWorkbook = context.workbook;
    let activeCell = myWorkbook.getActiveCell();
    activeCell.load("address");

    await context.sync();
    
    console.log("The active cell is " + activeCell.address);
});

getActiveChart()

获取工作簿中的当前活动图表。Gets the currently active chart in the workbook. 如果没有活动图表, 则会引发ItemNotFound异常。If there is no active chart, an ItemNotFound exception is thrown.

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

getActiveChart(): Excel.Chart;

返回

getActiveChartOrNullObject()

获取工作簿中的当前活动图表。Gets the currently active chart in the workbook. 如果没有活动图表, 则返回 null 对象。If there is no active chart, a null object is returned.

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

getActiveChartOrNullObject(): Excel.Chart;

返回

getActiveSlicer()

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取工作簿中当前处于活动状态的切片器。Gets the currently active slicer in the workbook. 如果没有活动切片器, 则会ItemNotFound引发异常。If there is no active slicer, an ItemNotFound exception is thrown.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

getActiveSlicer(): Excel.Slicer;

返回

getActiveSlicerOrNullObject()

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

获取工作簿中当前处于活动状态的切片器。Gets the currently active slicer in the workbook. 如果没有处于活动状态的切片器,则返回 null 对象。If there is no active slicer, a null object is returned.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

getActiveSlicerOrNullObject(): Excel.Slicer;

返回

getIsActiveCollabSession()

如果多个用户正在编辑工作簿(共同创作),则为 True。True if the workbook is being edited by multiple users (co-authoring). 请注意, 当工作簿状态发生变化以及更改在方法结果上反映时, 可能会有一些延迟。Please be aware there might be some delay between when the workbook status changes and when the changes are reflected on the result of the method.

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

getIsActiveCollabSession(): OfficeExtension.ClientResult<boolean>;

返回

OfficeExtension.ClientResult<boolean>

getSelectedRange()

从工作簿中获取当前选定的单个区域。Gets the currently selected single range from the workbook. 如果选择了多个区域, 则此方法将引发错误。If there are multiple ranges selected, this method will throw an error.

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

getSelectedRange(): Excel.Range;

返回

示例Examples

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

getSelectedRanges()

从工作簿中获取当前选定的一个或多个区域。Gets the currently selected one or more ranges from the workbook. 与 getSelectedRange() 不同,此方法返回表示所有选定区域的 RangeAreas 对象。Unlike getSelectedRange(), this method returns a RangeAreas object that represents all the selected ranges.

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

getSelectedRanges(): Excel.RangeAreas;

返回

示例Examples

await Excel.run(async (context) => {

    const selectedRanges = context.workbook.getSelectedRanges();
    selectedRanges.format.fill.color = "lightblue";

    await context.sync();
})

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.WorkbookLoadOptions): Excel.Workbook;

参数

返回

注解

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

load(option?: string | string[]): Excel.Workbook-Where 选项是一个逗号分隔的字符串或一个字符串数组, 用于指定要加载的属性。load(option?: string | string[]): Excel.Workbook - 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.Workbook-Where 选项。选择是一个用逗号分隔的字符串, 用于指定要加载的属性和选项。 expand 是一个用逗号分隔的字符串, 用于指定要加载的导航属性。load(option?: { select?: string; expand?: string; }): Excel.Workbook - 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.Workbook-仅适用于集合类型。load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Workbook - 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.Workbook;

参数

propertyNames
string | string[]

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

返回

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.Workbook;

参数

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.

返回

save(saveBehavior)

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

保存当前工作簿。Save current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

save(saveBehavior?: Excel.SaveBehavior): void;

参数

saveBehavior
Excel.SaveBehavior

保存工作簿的行为。workbook save behavior.

返回

void

示例Examples

await Excel.run(async (context) => {
    context.workbook.save(Excel.SaveBehavior.save);
});

save(saveBehaviorString)

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

保存当前工作簿。Save current workbook.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

save(saveBehaviorString?: "Save" | "Prompt"): void;

参数

saveBehaviorString
"Save" | "Prompt"

保存工作簿的行为。workbook save behavior.

返回

void

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.WorkbookUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Interfaces.WorkbookUpdateData

一个 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.Workbook): void

set(properties)

基于现有加载的对象同时设置该对象的多个属性。Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.Workbook): void;

参数

properties
Excel.Workbook

返回

void

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.WorkbookData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Workbook object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.WorkbookData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.WorkbookData;

返回

事件详细信息

onAutoSaveSettingChanged

在工作簿上更改“自动保存”设置时发生。Occurs when the autoSave setting is changed on the workbook.

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

readonly onAutoSaveSettingChanged: OfficeExtension.EventHandlers<Excel.WorkbookAutoSaveSettingChangedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorkbookAutoSaveSettingChangedEventArgs>

onSelectionChanged

文档中的选择更改时发生。Occurs when the selection in the document is changed.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

readonly onSelectionChanged: OfficeExtension.EventHandlers<Excel.SelectionChangedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.SelectionChangedEventArgs>