セルの保護

セルの保護

Aspose.Cells.GridWeb は、コントロールが 編集モード (デフォルトモード) にある場合に、セルの保護レベルを制御するためのいくつかの異なる技術を提供しています。これにより、エンドユーザーによるセルの変更を防ぐことができます。

すべてのセルを読み取り専用にする

ワークシートのすべてのセルを読み取り専用に設定するには、ワークシートのSetAllCellsReadonlyメソッドを呼び出します。

// 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メソッドの逆の効果を持ちます。

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

選択したセルを読み取り専用にする

特定のセル範囲のみを保護するには:

  1. SetAllCellsEditableメソッドを呼び出して、まずすべてのセルを編集可能にします。
  2. ワークシートのSetReadonlyRangeメソッドを呼び出して、保護するセルの範囲を指定します。このメソッドは、行数と列数を指定してセルの範囲を取得します。
// 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);

選択したセルを編集可能にする

特定のセル範囲の保護を解除するには:

  1. SetAllCellsReadonlyメソッドを呼び出して、まずすべてのセルを読み取り専用にします。
  2. ワークシートのSetEditableRangeメソッドを呼び出して、編集可能にするセルの範囲を指定します。このメソッドは、行数と列数を指定してセルの範囲を取得します。
// 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);