Version

Disabling Editing of a Worksheet (Infragistics Excel Engine)

You can disable editing of a worksheet by protecting it using the Worksheet object’s Protect method. This method has a lot of bool arguments one of which is to disallow cell editing. When a worksheet is protected all subsequent calls to the Protect method are ignored. To change the protections parameters you have to unprotect the worksheet using the Unprotect method and invoke the Protect method again with the new protection settings set in its arguments. You can check if a worksheet is protected using the IsProtected property.

Note
Note

The protection is not enforced via the Infragistics Excel Engine's object model. It is a responsibility of the UI visualizing this object model, to honor these protection settings and allow or restrict the user from performing the corresponding operations.

You can also use the Workbook object’s Protect method to protect a workbook against structural changes like adding, renaming, reordering and deleting of worksheets.

When protection is set, you can set the CellFormat object’s Locked property on individual cells, rows, merged cell regions, or columns to override the worksheet object’s protection on those objects. For example, if you need all cells of a worksheet to be read-only except for the cells of one column, you can protect the worksheet and then set the CellFormat property’s Locked property to False on a specific WorksheetColumn object. This will allow your end users to edit cells within the column while disabling editing of the other cells in the worksheet.

The following code shows you how to make one column editable while all other cells are read-only in a worksheet.

In Visual Basic:

Imports Infragistics.Documents.Excel
...
worksheet1.Protect(DirectCast(Nothing, System.Nullable(Of Boolean)))
worksheet1.Columns(1).CellFormat.Locked = ExcelDefaultableBoolean.False

In C#:

using Infragistics.Documents.Excel;
...
worksheet1.Protect((bool?)null);
worksheet1.Columns[1].CellFormat.Locked = ExcelDefaultableBoolean.False;