Is there a way to use Excel's 'Protect Worksheet' and/or 'Protect Workbook' options? #457

Closed
opened 2016-08-15 04:05:15 +00:00 by reggaemahn · 3 comments
reggaemahn commented 2016-08-15 04:05:15 +00:00 (Migrated from github.com)

Hey,

Thanks for the awesome work on this library.

I was wondering if you could password protect worksheets and/or workbooks with this library. Or if there was an alternate way which could stop users from being able to modify the structural integrity of an xlsx document?

Hey, Thanks for the awesome work on this library. I was wondering if you could password protect worksheets and/or workbooks with this library. Or if there was an alternate way which could stop users from being able to modify the structural integrity of an xlsx document?
AlexanderKozhevin commented 2016-11-04 12:56:19 +00:00 (Migrated from github.com)

👍

👍
SheetJSDev commented 2017-04-13 08:02:42 +00:00 (Migrated from github.com)

The protect worksheet options are exposed in the worksheet !protect key, as explained in https://github.com/sheetjs/js-xlsx#worksheet-object .

The protect workbook option is not currently read or saved. However, if you are feeling adventurous, it's not difficult to add in!

The workbook protection info is stored in a workbookProtection tag. On the write side, it should be placed in the position of the workbookProtection comment.

To stop users from modifying the structure of the workbook, it would suffice to add something like:

o[o.length] = writextag('workbookProtection', null, {lockStructure:"1", workbookPassword:crypto_CreatePasswordVerifier_Method1(password).toString(16).toUpperCase()});

where password is the password string.

If you would like to send a PR, consider adding a !protect key to the workbook similar to the sheet object.

The protect worksheet options are exposed in the worksheet `!protect` key, as explained in https://github.com/sheetjs/js-xlsx#worksheet-object . The protect workbook option is not currently read or saved. However, if you are feeling adventurous, it's not difficult to add in! The workbook protection info is stored in a workbookProtection tag. On the write side, it should be placed [in the position of the workbookProtection comment](https://github.com/SheetJS/js-xlsx/blob/master/bits/72_wbxml.js#L168). To stop users from modifying the structure of the workbook, it would suffice to add something like: ```js o[o.length] = writextag('workbookProtection', null, {lockStructure:"1", workbookPassword:crypto_CreatePasswordVerifier_Method1(password).toString(16).toUpperCase()}); ``` where `password` is the password string. If you would like to send a PR, consider adding a `!protect` key to the workbook similar to the sheet object.
SheetJSDev commented 2021-09-14 02:55:11 +00:00 (Migrated from github.com)
[Protect Worksheet is documented](https://github.com/SheetJS/sheetjs#worksheet-object) while [Protect Workbook will require a Pro build](https://sheetjs.com/pro)
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#457
No description provided.