Posted 22 July 2024, 2:36 am EST
- Updated 22 July 2024, 2:41 am EST
Hi,
Regarding your query “For protecting a sheet, is there any way we can capture an event when the user clicks ‘OK’?”, you can use addListener to monitor when the “OK” button is clicked. Please refer to the attached snippet and the gif “Steps.gif”:
spread.commandManager().addListener("app", (args) => {
if(args.command.cmd == "Designer.confirmProtectSheet"){
console.log("Ok is clicked:", args);
}
});
Gif: ![](https://discourse.mescius.io/uploads/default/original/2X/8/87b0e183a3966c5e9d1f9ba2184d51e153edba67.gif)
Designer: https://developer.mescius.com/spreadjs/designer/index.html
Regarding your second query, “However, for the other link you shared, it is just protecting the export and import functionality. In the current desktop Spread.NET, when we protect a workbook, you can’t add or hide/unhide sheets without a password,” my understanding is that you want to set a password when exporting through code.
You can achieve this by referring to the snippet below, which is also used in the attached demo sample:
let password = "spreadjs2023";
spread.export(blob => saveAs(blob, "encrypted-export.xlsx"), console.log, {
fileType: GC.Spread.Sheets.FileType.excel,
password: password
});
Demo: https://developer.mescius.com/spreadjs/demos/features/spreadjs-file-format/password/purejs#demo_source_name
If there is any difference in my understanding, to better assist you, could you please elaborate and share your exact use case with some examples?
Regards,
Priyam