如何在Excel中唯一标识工作簿

问题描述

我们有一个基于用户角色的功能的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();

参考链接-https://docs.microsoft.com/en-us/javascript/api/office/office.settings?view=word-js-preview#saveasync-options--callback-

,

是的,您可以使用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/office/dev/add-ins/excel/excel-add-ins-workbooks#worksheet-level-custom-properties

https://docs.microsoft.com/en-us/javascript/api/office/office.document?view=excel-js-1.12

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...