保护 Cells
Contents
[
Hide
]
本主题介绍了一些用于保护单元格的技术。使用这些技术允许开发人员限制用户编辑工作表中的所有或选定范围的单元格。
保护 Cells
Aspose.Cells.GridWeb 提供了几种不同的技术来控制单元格的保护级别,当控件处于编辑模式(默认模式)。这可以保护单元不被最终用户修改。
使所有 Cells 只读
要将工作表中的所有单元格设置为只读,请调用工作表的 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(); |
使所有 Cells 可编辑
要取消对所有单元格的保护,请调用工作表的 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(); |
使选定的 Cells 只读
仅保护一定范围的单元格:
- 首先通过调用 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); |
使选定的 Cells 可编辑
要取消对一系列单元格的保护:
- 通过调用 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); |