Spread JS allows users to protect the sheet and lock cells in the widget.
Protecting the sheet prevents cells from being edited. If you wish to allow the user to edit specific cells, protect the sheet and unlock only the cells you want the user to edit. Data can be copied from locked cells.
In order to protect a worksheet, you need to set the isProtected option to true. In order to lock a cell, you can use the locked method.
The options.protectionOptions property can be used to specify what areas you want the user to be allowed to change. Areas can include resizing, dragging, inserting or deleting rows or columns, and so on.
When the isProtected option is set to true, the following properties will take effect in the below mentioned ways:
- allowDragInsertRows - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to perform the drag operation while inserting rows.
- allowDragInsertColumns - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to perform the drag operation while inserting columns.
- allowInsertRows - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to insert rows.
- allowInsertColumns - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to insert columns.
- allowDeleteRows - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to delete rows.
- allowDeleteColumns - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to delete columns.
- allowSelectLockedCells - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to select locked cells.
- allowSelectUnlockedCells - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to select unlocked cells.
- allowSort - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to sort ranges.
- allowFilter - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to filter ranges.
- allowEditObjects - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to edit floating objects.
- allowResizeRows - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to resize rows.
- allowResizeColumns - The default value of this option is not defined. When this option is set to false, it doesn't allow the user to resize columns.
When the isProtected option is set to false, the above protection options will not take any effect.
Using Code
This example unlocks a cell.
JavaScript |
Copy Code
|
sheet.getCell(1,1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
sheet.setValue(1,1,"unLocked");
sheet.getRange(-1,3, -1, 1).locked(false);
sheet.getRange(5, -1, 1, -1).locked(false);
sheet.options.isProtected = true; |
This example protects the worksheet using various protection options that are available in Spread JS.
JavaScript |
Copy Code
|
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var sheet = spread.getActiveSheet();
sheet.options.isProtected = true;
sheet.options.protectionOptions.allowDeleteRows = true;
sheet.options.protectionOptions.allowDeleteColumns = true;
sheet.options.protectionOptions.allowInsertRows = true;
sheet.options.protectionOptions.allowInsertColumns = true;
sheet.options.protectionOptions.allowDargInsertRows = true;
sheet.options.protectionOptions.allowDragInsertColumns = true; |
Note: The protection options : allowInsertRows, allowInsertColumns, allowDeleteRows and allowDeleteColumns are available only when you are performing an operation on the user interface. In other words, the value will only restrict insertion and deletion of rows and columns command in the context menu.