我正在尝试使用office查看自定义属性的存在。我很难了解它的存在。
Excel.run(async (context) => {
let customDocProperties = context.workbook.properties.custom;
let customProperty = customDocProperties.getItem("prop");
customProperty.load("key, value");
await context.sync();
console.log(customProperty);
}在上述情况下,如果可用的属性“支柱”,代码工作良好,没有任何问题。如果没有“支柱”或任何可用的自定义属性,代码就不会继续进行下去。
如果没有这样的属性或没有可用的自定义属性,如何破解代码?
另外,我尝试了以下代码。在这种情况下,当有任何自定义属性可用时,代码挂起,excel内存(在GBs中)急剧上升。
customDocProperties.load('items');
await context.sync();
console.log(customDocProperties.items.length);谢谢
发布于 2018-06-11 22:32:11
尝试使用getItemOrNullObject()而不是getItem()。以下是一个例子:
Excel.run(async (context) => {
let customDocProperties = context.workbook.properties.custom;
let customProperty = customDocProperties.getItemOrNullObject("prop");
customProperty.load("key, value");
await context.sync();
if (customProperty.isNullObject) {
//Handle case where the custom property does not exist.
}
else
console.log(customProperty);
})
}有关更多信息,请参见CustomPropertyCollection。
https://stackoverflow.com/questions/50806657
复制相似问题