1

How can we lock certain cells in excel by using SheetJs ws['!protect']

There is a Worksheet Protection Details section which has some keys but there usage is not clear from the documentation.

https://github.com/SheetJS/sheetjs/blob/master/README.md

If somebody has used it or have any idea please help me.

gaurav rathor
  • 187
  • 1
  • 2
  • 9

1 Answers1

0

I had the same issue. Yes, the documentation did not mention much except the keys [https://docs.sheetjs.com/docs/csf/sheet][1]

From the code in their [github][2] and after testing it as well: ws['!protect'] requires an object.

The schema of the object is as follows(in typescript):

  {
    password?: string,
    selectLockedCells?: boolean,
    selectUnlockedCells?: boolean,
    formatCells?: boolean,
    formatColumns?: boolean,
    formatRows?: boolean,
    insertColumns?: boolean,
    insertRows?: boolean,
    insertHyperlinks?: boolean,
    deleteColumns?: boolean,
    deleteRows?: boolean,
    sort?: boolean,
    autoFilter?: boolean,
    pivotTables?: boolean,
    objects?: boolean,
    scenarios?: boolean,
   }

All keys are optional [1]: https://docs.sheetjs.com/docs/csf/sheet [2]: https://github.com/SheetJS/sheetjs/blob/5b4806bff01a9f4289b4c04e8a60a6c4c52fe93a/xlsx.js#L15292

Yash
  • 1
  • 1
  • 1