【问题标题】:How to uniquely identify a work book in excel如何在excel中唯一标识一个工作簿
【发布时间】:2020-10-19 13:25:14
【问题描述】:

我们有一个带有基于用户角色的功能的 Excel 插件。我们有一个想法,即创建一个具有所有功能访问权限的示例工作簿以用于演示目的。我们在 excel 中有工作簿的唯一标识符吗?如果存在,我们如何使用 officejs 访问它们。我们对 officejs 文档进行了研究,发现工作簿中的 Worksheets 具有唯一标识符。缺点是在删除工作表并创建新工作表时会重复使用这些 id。

Reference link of worksheet documentation .

【问题讨论】:

    标签: excel office-js office-addins excel-addins


    【解决方案1】:

    请尝试使用以下 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-

    【讨论】:

    • 谢谢你,这似乎可以完成这项工作
    【解决方案2】:

    是的,您可以使用 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

    【讨论】:

    • 感谢您的建议。 Office.context.document.url API 似乎返回文件位置 URL,并且当我们关闭 excel 文档时,工作表/工作簿级别的自定义属性被清除。我们正在寻找一种可以识别文档的方法,例如即使在共享文档时也是相同的唯一标识符键
    猜你喜欢
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多