问题描述
我们有一个基于用户角色的功能的excel插件。我们有一个创建带有所有功能访问权限的示例工作簿的想法,以进行演示。我们在excel中是否有工作簿的唯一标识符?如果存在,我们如何使用officejs访问它们。我们对officejs文档进行了研究,发现工作簿中的工作表具有唯一的标识符。缺点是删除工作表并创建新工作表时,这些ID将被重用。
Reference link of worksheet documentation 。
解决方法
请尝试使用以下Officejs API将UDID与工作簿一起保存。这将保留在工作簿中。
Office.context.document.settings.set(“ Worksheet_ID”,'your_unique_identifier''); Office.context.document.settings.saveAsync();
,是的,您可以使用office.document.url
属性来标识工作簿URL。
此外,您还可以在工作表级别上设置/获取自定义属性:
Excel.run(function (context) {
// Add the custom property.
var customWorksheetProperties = context.workbook.worksheets.getActiveWorksheet().customProperties;
customWorksheetProperties.add("WorksheetGroup","Alpha");
return context.sync();
}).catch(errorHandlerFunction);
[...]
Excel.run(function (context) {
// Load the keys and values of all custom properties in the current worksheet.
var worksheet = context.workbook.worksheets.getActiveWorksheet();
worksheet.load("name");
var customWorksheetProperties = worksheet.customProperties;
var customWorksheetProperty = customWorksheetProperties.getItem("WorksheetGroup");
customWorksheetProperty.load(["key","value"]);
return context.sync().then(function() {
// Log the WorksheetGroup custom property to the console.
console.log(worksheet.name + ": " + customWorksheetProperty.key); // "WorksheetGroup"
console.log(" Custom value : " + customWorksheetProperty.value); // "Alpha"
});
}).catch(errorHandlerFunction);
https://docs.microsoft.com/en-us/javascript/api/office/office.document?view=excel-js-1.12