Add Protection in Worksheet
Contents
[
Hide
]
Aspose.Cells for GridDesktop allows you to protect cells in a worksheet.First you need to protect your worksheet, then you can protect your desired cells in the worksheet. In order to protect worksheet, please set Worksheet.Protected property to true, then use Worksheet.SetProtected() method to protect the range of cells.
Protect Cell using Aspose.Cells.GridDesktop
The following sample code protects all the cells in range A1:B1 of the active worksheet of GridDesktop. When you will double click any cell in this range, you will not able to edit. It will make these cells readonly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Make sure sheet has been protected | |
sheet.Protected = true; | |
// Choose a cell range | |
CellRange range = sheet.CreateRange("A1", "B1"); | |
// Set protected range area on Worksheet | |
sheet.SetProtected(range, true); |