【发布时间】:2020-01-29 13:28:10
【问题描述】:
我们已经构建了一个 Excel 任务窗格插件,主要用于工作表。根据我们的要求,每当用户关闭 excel 并重新打开它时,我们希望使用唯一 ID 识别 excel。
从工作簿加载 excel ID 的示例代码:
Office.initialize = () => {
Excel.run(function(context) {
var sheet = context.workbook.worksheets.getItem("Sheet1");
const worksheets = context.workbook.worksheets;
//tried to load ID property using below code
worksheets.load("id, name");
worksheets.load(["items/id", "items/name"]);
worksheets.load(["id", "name", "worksheet/id"]);
sheet.load(["items/id", "items/name"]);
context.sync();
//below is the code to print excel ID
console.log(sheet.id);
// OR
worksheets.items.forEach(ws => {
console.log(`id: ${ws.id}, name: ${ws.name}`)
});
}).catch(function(error) {
console.log(error.debugInfo);
});
}
我们收到以下错误:
未捕获的 RichApi.Error:属性“id”不可用。在读取属性值之前,调用包含对象的 load 方法,并在关联的请求上下文中调用“context.sync()”。
【问题讨论】:
-
您尝试过:
sheet.load('id');或sheet.load({ id: true});吗? Link to doc -
尝试使用 sheet.load('id')
-
我发布了一个包含解决方案的答案 :)
-
感谢 Lumpenstein。它真的很有帮助。
标签: javascript excel office365 office-js office365api