Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Introducedin
8.7
8.7
Description

Excerpt

A SheetProtection object contains sheet level protection properties that control what users can interact with when a worksheet is protected.

To access SheetProtection, use Worksheet.SheetProtection.

Signature
C#
C#
 public sealed class SheetProtection
Signature
vb.net
vb.net
Public NotInheritable Class SheetProtection
Remarks

In a new workbook, AllowSelectLockedCells and AllowSelectUnlockedCells default to true. The rest of the properties default to false.

The SheetProtection properties will only take effect if the worksheet is protected. Worksheets can be protected with Worksheet.Protect(String). If the worksheet is not protected, the values of the properties will persist, but will not have an effect.

Example
Code Block
csharp
csharp
titleC#

          //--- Open existing spreadsheet
          ExcelApplication xla = new ExcelApplication();
          Workbook wb = xla.Open(@"C:\MySpreadsheet.xlsx");

          //--- Get SheetProtection
          SheetProtection protection = wb[0].SheetProtection;

          //--- Set Properties
          protection.AllowFormatCells = true;
          protection.AllowSort = false;

        
Code Block
vbnet
vbnet
titlevb.net

          '--- Open existing spreadsheet
          Dim xla As New ExcelApplication()
          Dim wb As Workbook = xla.Open("C:\MySpreadsheet.xlsx")

          '--- Get SheetProtection
          Dim protection As SheetProtection = wb(0).SheetProtection

          '--- Set Properties
          protection.AllowFormatCells = true;
          protection.AllowSort = false;

        
Properties

Name

Description

AllowSelectLockedCells

Excerpt Include
EW8:SheetProtection.AllowSelectLockedCells
EW8:SheetProtection.AllowSelectLockedCells
nopaneltrue

AllowSelectUnlockedCells

Excerpt Include
EW8:SheetProtection.AllowSelectUnlockedCells
EW8:SheetProtection.AllowSelectUnlockedCells
nopaneltrue

AllowFormatCells

Excerpt Include
EW8:SheetProtection.AllowFormatCells
EW8:SheetProtection.AllowFormatCells
nopaneltrue

AllowFormatRows

Excerpt Include
EW8:SheetProtection.AllowFormatRows
EW8:SheetProtection.AllowFormatRows
nopaneltrue

AllowFormatColumns

Excerpt Include
EW8:SheetProtection.AllowFormatColumns
EW8:SheetProtection.AllowFormatColumns
nopaneltrue

AllowInsertColumns

Excerpt Include
EW8:SheetProtection.AllowInsertColumns
EW8:SheetProtection.AllowInsertColumns
nopaneltrue

AllowInsertRows

Excerpt Include
EW8:SheetProtection.AllowInsertRows
EW8:SheetProtection.AllowInsertRows
nopaneltrue

AllowInsertHyperlinks

Excerpt Include
EW8:SheetProtection.AllowInsertHyperlinks
EW8:SheetProtection.AllowInsertHyperlinks
nopaneltrue

AllowDeleteColumns

Excerpt Include
EW8:SheetProtection.AllowDeleteColumns
EW8:SheetProtection.AllowDeleteColumns
nopaneltrue

AllowDeleteRows

Excerpt Include
EW8:SheetProtection.AllowDeleteRows
EW8:SheetProtection.AllowDeleteRows
nopaneltrue

AllowSort

Excerpt Include
EW8:SheetProtection.AllowSort
EW8:SheetProtection.AllowSort
nopaneltrue

AllowUseAutoFilter

Excerpt Include
EW8:SheetProtection.AllowUseAutoFilter
EW8:SheetProtection.AllowUseAutoFilter
nopaneltrue

AllowUsePivotTableReports

Excerpt Include
EW8:SheetProtection.AllowUsePivotTableReports
EW8:SheetProtection.AllowUsePivotTableReports
nopaneltrue