Introduction
In this topic, we will describe few useful techniques for the developers to help them in protecting their cells in a more precise manner. Using these techniques, developers can restrict users from editing all or a selected range of cells of their worksheets.
Protecting Cells
When Aspose.Grid.Web is in Edit Mode (which is the default mode of GridWeb control), developers may like to protect all or some selected cells of their worksheets from being modified by users. To facilitate such requirements of developers, Aspose.Grid.Web provides few techniques to control the protection level of cells. Let's discuss them one by one.
Making All Cells Readonly
Developers can make all cells of their worksheets to Readonly state by calling SetAllCellsReadonly method of the worksheet.
Example:
[C#]
//Accessing the reference of the worksheet that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Setting all cells of the worksheet to Readonly
sheet.SetAllCellsReadonly();
[VB.NET]
'Accessing the reference of the worksheet that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Setting all cells of the worksheet to Readonly
sheet.SetAllCellsReadonly()
Making All Cells Editable
Developers can also unprotect cells by calling SetAllCellsEditable method of the worksheet. This method works in reverse to SetAllCellsReadonly method of the worksheet.
Example:
[C#]
//Accessing the reference of the worksheet that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Setting all cells of the worksheet to Editable
sheet.SetAllCellsEditable();
[VB.NET]
'Accessing the reference of the worksheet that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Setting all cells of the worksheet to Editable
sheet.SetAllCellsEditable()
Making Selected Cells Readonly
To protect only a selected range of cells, developers would first need to make all cells Editable by calling SetAllCellsEditable method. Once all cells become editable then developers can specify the range of cells that are required to be read only by calling SetReadonlyRange method of the worksheet. This method takes the number of rows and columns to specify the range of cells.
Example:
[C#]
//Accessing the reference of the worksheet that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Setting all cells of the worksheet to Editable first
sheet.SetAllCellsEditable();
//Finally, Setting selected cells of the worksheet to Readonly
sheet.SetReadonlyRange(3, 2, 4, 1);
[VB.NET]
'Accessing the reference of the worksheet that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Setting all cells of the worksheet to Editable first
sheet.SetAllCellsEditable()
'Finally, Setting selected cells of the worksheet to Readonly
sheet.SetReadonlyRange(3, 2, 4, 1)
Making Selected Cells Editable
To unprotect only a selected range of cells, developers would first need to make all cells Readonly by calling SetAllCellsReadonly method. Once all cells become read only then developers can specify the range of cells that are only required to be editable by calling SetEditableRange method of the worksheet. This method takes the number of rows and columns to specify the range of cells.
Example:
[C#]
//Accessing the reference of the worksheet that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Setting all cells of the worksheet to Readonly first
sheet.SetAllCellsReadonly();
//Finally, Setting selected cells of the worksheet to Editable
sheet.SetEditableRange(3, 2, 4, 1);
[VB.NET]
'Accessing the reference of the worksheet that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Setting all cells of the worksheet to Readonly first
sheet.SetAllCellsReadonly()
'Finally, Setting selected cells of the worksheet to Editable
sheet.SetEditableRange(3, 2, 4, 1)
Describes how to deal with different kinds of modes supported by Aspose.Grid.Web.
7/5/2007 11:37:58 PM - -222.190.3.243