Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Introducedin
8.6.1
8.6.1
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.xlsxlsx");

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

BackgroundColor AllowSelectLockedCells

Excerpt Include
EW8:StyleSheetProtection.BackgroundColorAllowSelectLockedCellsEW8:Style
SheetProtection.BackgroundColorAllowSelectLockedCells
nopaneltrue

Border AllowSelectUnlockedCells

Excerpt Include
EW8:StyleSheetProtection.BorderAllowSelectUnlockedCellsEW8:Style
SheetProtection.BorderAllowSelectUnlockedCells
nopaneltrue

CellLocked AllowFormatCells

Excerpt Include
EW8:StyleSheetProtection.CellLockedAllowFormatCellsEW8:Style
SheetProtection.CellLockedAllowFormatCells
nopaneltrue

Font AllowFormatRows

Excerpt Include
EW8:StyleSheetProtection.FontAllowFormatRowsEW8:Style
SheetProtection.FontAllowFormatRows
nopaneltrue

ForegroundColor AllowFormatColumns

Excerpt Include
EW8:StyleSheetProtection.ForegroundColorAllowFormatColumnsEW8:Style
SheetProtection.ForegroundColorAllowFormatColumns
nopaneltrue

HideFormulas AllowInsertColumns

Excerpt Include
EW8:StyleSheetProtection.HideFormulasAllowInsertColumnsEW8:Style
SheetProtection.HideFormulasAllowInsertColumns
nopaneltrue

HorizontalAlignment AllowInsertRows

Excerpt Include
EW8:StyleSheetProtection.HorizontalAlignmentAllowInsertRowsEW8:Style
SheetProtection.HorizontalAlignmentAllowInsertRows
nopaneltrue

IndentLevel AllowInsertHyperlinks

Excerpt Include
EW8:StyleSheetProtection.IndentLevelAllowInsertHyperlinksEW8:Style
SheetProtection.IndentLevelAllowInsertHyperlinks
nopaneltrue

JustifyDistributed AllowDeleteColumns

Excerpt Include
EW8:StyleSheetProtection.JustifyDistributedAllowDeleteColumnsEW8:Style
SheetProtection.JustifyDistributedAllowDeleteColumns
nopaneltrue

NumberFormat AllowDeleteRows

Excerpt Include
EW8:StyleSheetProtection.NumberFormatAllowDeleteRowsEW8:Style
SheetProtection.NumberFormatAllowDeleteRows
nopaneltrue

Orientation AllowSort

Excerpt Include
EW8:StyleSheetProtection.OrientationAllowSortEW8:Style
SheetProtection.OrientationAllowSort
nopaneltrue

Pattern AllowUseAutoFilter

Excerpt Include
EW8:StyleSheetProtection.PatternAllowUseAutoFilterEW8:Style
SheetProtection.PatternAllowUseAutoFilter
nopaneltrue

ShrinkToFit AllowUsePivotTableReports

Excerpt Include
EW8:StyleSheetProtection.ShrinkToFitAllowUsePivotTableReportsEW8:Style
SheetProtection.ShrinkToFitAllowUsePivotTableReports
nopaneltrue

TextDirection

Excerpt Include
EW8:Style.TextDirectionEW8:Style.TextDirection
nopaneltrue

VerticalAlignment

Excerpt Include
EW8:Style.VerticalAlignmentEW8:Style.VerticalAlignment
nopaneltrue

WrapText

Excerpt Include
EW8:Style.WrapTextEW8:Style.WrapText
nopaneltrue