Excel.SettingCollection class

表示属于工作簿的键值对设置对象的集合。 范围仅限于每个文件和外接程序 (任务窗格或内容) 组合。

Extends

注解

[ API 集:ExcelApi 1.4 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

items

获取此集合中已加载的子项。

方法

add(key, value)

设置指定的 Setting 对象,或将其添加到工作簿中。

getCount()

获取集合中的设置数。

getItem(key)

通过键获取设置项。

getItemOrNullObject(key)

通过键获取设置项。 如果该设置不存在,则此方法返回一个 对象,其 isNullObject 属性设置为 true。 有关详细信息,请参阅 *OrNullObject 方法和属性

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来,调用toJSON传递给它的 对象的 方法。) 虽然原始Excel.SettingCollection对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.SettingCollectionData) ,其中包含一个“items”数组,其中包含集合项中任何已加载属性的浅表副本。

事件

onSettingsChanged

更改文档中的设置时发生。

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

items

获取此集合中已加载的子项。

readonly items: Excel.Setting[];

属性值

方法详细信息

add(key, value)

设置指定的 Setting 对象,或将其添加到工作簿中。

add(key: string, value: string | number | boolean | Date | any[] | any): Excel.Setting;

参数

key

string

新设置的键。

value

string | number | boolean | Date | any[] | any

新设置的值。

返回

注解

[ API 集:ExcelApi 1.4 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-workbook-and-worksheet-collection.yaml

await Excel.run(async (context) => {
    const settings = context.workbook.settings; 
    settings.onSettingsChanged.add(onChangedSetting);

    await context.sync();
    console.log("Settings changed handler registered.");
});

getCount()

获取集合中的设置数。

getCount(): OfficeExtension.ClientResult<number>;

返回

注解

[ API 集:ExcelApi 1.4 ]

getItem(key)

通过键获取设置项。

getItem(key: string): Excel.Setting;

参数

key

string

设置的键。

返回

注解

[ API 集:ExcelApi 1.4 ]

getItemOrNullObject(key)

通过键获取设置项。 如果该设置不存在,则此方法返回一个 对象,其 isNullObject 属性设置为 true。 有关详细信息,请参阅 *OrNullObject 方法和属性

getItemOrNullObject(key: string): Excel.Setting;

参数

key

string

设置的键。

返回

注解

[ API 集:ExcelApi 1.4 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/50-workbook/create-get-change-delete-settings.yaml

await Excel.run(async (context) => {
    const settings = context.workbook.settings;
    let needsReview = settings.getItem("NeedsReview");
    needsReview.delete();
    needsReview = settings.getItemOrNullObject("NeedsReview");

    await context.sync();

    if (needsReview.isNullObject) {
        console.log("The setting has been deleted");
    } else {
        console.log("The setting was not deleted");
    }

    await context.sync();
});

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: Excel.Interfaces.SettingCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.SettingCollection;

参数

options

Excel.Interfaces.SettingCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Excel.SettingCollection;

参数

propertyNamesAndPaths
OfficeExtension.LoadOption

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来,调用toJSON传递给它的 对象的 方法。) 虽然原始Excel.SettingCollection对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.SettingCollectionData) ,其中包含一个“items”数组,其中包含集合项中任何已加载属性的浅表副本。

toJSON(): Excel.Interfaces.SettingCollectionData;

返回

事件详细信息

onSettingsChanged

更改文档中的设置时发生。

readonly onSettingsChanged: OfficeExtension.EventHandlers<Excel.SettingsChangedEventArgs>;

事件类型

注解

[ API 集:ExcelApi 1.4 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-workbook-and-worksheet-collection.yaml

await Excel.run(async (context) => {
    const settings = context.workbook.settings; 
    settings.onSettingsChanged.add(onChangedSetting);

    await context.sync();
    console.log("Settings changed handler registered.");
});