在工作表中添加保护

使用Aspose.Cells.GridDesktop保护单元格

以下示例代码保护了GridDesktop活动工作表中范围A1:B1中的所有单元格。当您双击此范围内的任何单元格时,您将无法编辑它们。这将使这些单元格为只读。

// 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);