保护单元格
Contents
[
Hide
]
本主题描述了保护单元格的几种技术。使用这些技术可让开发人员限制用户对工作表中所有或选定范围的单元格进行编辑。
保护单元格
当控件处于编辑模式(默认模式)时,Aspose.Cells.GridWeb提供了几种不同的技术来控制单元格的保护级别。这样可以防止最终用户修改单元格。
设置所有单元格为只读
要将工作表中的所有单元格设置为只读,请调用工作表的SetAllCellsReadonly方法。
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 reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Setting all cells of the worksheet to Readonly | |
sheet.SetAllCellsReadonly(); |
设置所有单元格为可编辑
要取消所有单元格的保护,请调用工作表的SetAllCellsEditable方法。该方法与SetAllCellsReadonly方法具有相反的效果。
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 reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Setting all cells of the worksheet to Editable | |
sheet.SetAllCellsEditable(); |
将选定的单元格设置为只读
仅保护一系列单元格:
- 首先通过调用SetAllCellsEditable方法使所有单元格可编辑。
- 通过调用工作表的SetReadonlyRange方法指定需保护的单元格范围。此方法采用行数和列数来指定单元格范围。
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 reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[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); |
使选定的单元格可编辑
取消保护一系列单元格:
- 通过调用SetAllCellsReadonly方法使所有单元格只读。
- 通过调用工作表的SetEditableRange方法指定可编辑的单元格范围。此方法采用行数和列数来指定单元格范围。
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 reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[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); |