Protect Worksheet in Office Scripts with Options

主宰稳场 提交于 2021-01-27 19:33:08

问题


How can I protect a worksheet but allow the user to format the columns in Office Scripts? I have tried a few things but haven't had any success.

function main(workbook: ExcelScript.Workbook) {
    let sheet = workbook.getWorksheet("By Item");
    sheet.getProtection().protect(ExcelScript.WorksheetProtectionOptions.allowFormatColumns);
}

Please see the attached link

https://docs.microsoft.com/en-us/javascript/api/office-scripts/excelscript/excelscript.worksheetprotection?view=office-scripts#protect-options--password-


回答1:


The protect() method takes an object as argument for the 1st argument. See below. I noticed that cell background/fill doesn't work even with this setting. All other formatting works such as font color, border, etc. That may be a bug that we'll follow-up on.

function main(workbook: ExcelScript.Workbook) {
    let sheet = workbook.getWorksheet("By Item");
    sheet.getProtection().unprotect();
    sheet.getProtection().protect({
        allowFormatCells: true
    });
}


来源:https://stackoverflow.com/questions/64393820/protect-worksheet-in-office-scripts-with-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!