如何在 Office Web 外接程序中注册设置已更改事件的处理程序



>我正在尝试使用 Excel 1.4 要求集中的 Excel.Setting 和Excel.SettingCollection对象。(不是共享 Office.js API 中的旧设置对象。我无法注册Excel.SettingCollection.onSettingsChanged事件的处理程序。下面是我的代码(打字稿(。我运行createSetting方法,并已验证是否正在添加我的设置。然后我运行changeSetting方法。没有错误,但我的处理程序永远不会运行。谁能看出出了什么问题?添加第二个设置和删除设置也不会触发处理程序。(其他 Excel 1.4 API 工作正常。

async function createSetting() {
try {
await Excel.run(async (context) => {
const settings = context.workbook.settings;
settings.add("NeedsReview", true);
settings.onSettingsChanged.add(onChangedSetting);
await context.sync();
});
}
catch (error){
console.log(error.message);
}
}

处理器:

async function onChangedSetting() {
try {
await Excel.run(async (context) => {
console.log("handler ran");  // DOES NOT RUN
await context.sync();
});
}
catch (error) {
console.log(error.message);
}
} 

更改设置方法:

async function changeSetting() {
try {
await Excel.run(async (context) => {
const settings = context.workbook.settings;
// The settings.add function is also how you change a 
// setting. There is no Excel.SettingCollection.setItem
// or Excel.Setting.set method.
settings.add("NeedsReview", false); // Change value
await context.sync();
});
}
catch (error) {
console.log(error.message);
}
}

我知道这是一个已知的错误。使用新的 1.4 API 更改设置时,不会触发onSettingsChanged事件。修复后,我将在此处更新。

相关内容

最新更新