Protect sheet and lock particular cells in Spreadsheet.
This article explains how to lock a particular cell in the JavaScript Spreadsheet component. You can lock spreadsheet cells by using the protectSheet and lockCells methods. Using the code below, you will be able to lock a particular cell in the spreadsheet.
[HTML]
<button class="e-btn" id="btn">Lock Cell</button> <div id="spreadsheet"></div>
[JS]
var spreadsheet = new ej.spreadsheet.Spreadsheet({
sheets: [ {
name: 'Car Sales Report',
ranges: [{ dataSource: defaultData }],
}, ],
});
//Render initialized Spreadsheet component
spreadsheet.appendTo('#spreadsheet');
document.getElementById('btn').onclick = () => {
//To Apply lock cell to the specified range of cells.
var protectSetting = {
selectCells: true,
formatCells: false,
formatRows: false,
formatColumns: false,
insertLink: false,
};
spreadsheet.protectSheet('Issues', protectSetting);
spreadsheet.lockCells('A2:AZ100', false); // to unlock the A2:AZ100 cells
spreadsheet.lockCells('A1:Z1', true); // to lock the A1:Z1 cells (A1 cell is locked within A1:AZ100)
};
Refer to the working sample for additional details and implementation: Sample
Output screenshot:
Before lock cell:

After lock cell:

Conclusion
We hope you enjoyed learning about how to protect sheet and lock particular cells in Spreadsheet.
You can refer to our JavaScript Spreadsheet page to learn about its other groundbreaking feature representations. You can also explore our JavaScript Spreadsheet Documentation to understand how to manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!