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}{signature:
}
Signature
vb.net
vb.net
Public NotInheritable Class SheetProtection
{signature}
{remarks}
In a new workbook, [AllowSelectLockedCells|SheetProtection.AllowSelectLockedCells] and [AllowSelectUnlockedCells|SheetProtection.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 [EW8:
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.

{remarks} {example}{code:csharp|title=C#}

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} {code:vbnet|title=
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;

        
{code} {example} {properties} || Name || Description || | [AllowSelectLockedCells|SheetProtection.AllowSelectLockedCells] | {excerpt-include:SheetProtection.AllowSelectLockedCells|nopanel=true} | | [AllowSelectUnlockedCells|SheetProtection.AllowSelectUnlockedCells] | {excerpt-include:SheetProtection.AllowSelectUnlockedCells|nopanel=true} | | [AllowFormatCells|SheetProtection.AllowFormatCells] | {excerpt-include:SheetProtection.AllowFormatCells|nopanel=true} | | [AllowFormatRows|SheetProtection.AllowFormatRows] | {excerpt-include:SheetProtection.AllowFormatRows|nopanel=true} | | [AllowFormatColumns|SheetProtection.AllowFormatColumns] | {excerpt-include:SheetProtection.AllowFormatColumns|nopanel=true} | | [AllowInsertColumns|SheetProtection.AllowInsertColumns] | {excerpt-include:SheetProtection.AllowInsertColumns|nopanel=true} | | [AllowInsertRows|SheetProtection.AllowInsertRows] | {excerpt-include:SheetProtection.AllowInsertRows|nopanel=true} | | [AllowInsertHyperlinks|SheetProtection.AllowInsertHyperlinks] | {excerpt-include:SheetProtection.AllowInsertHyperlinks|nopanel=true} | | [AllowDeleteColumns|SheetProtection.AllowDeleteColumns] | {excerpt-include:SheetProtection.AllowDeleteColumns|nopanel=true} | | [AllowDeleteRows|SheetProtection.AllowDeleteRows] | {excerpt-include:SheetProtection.AllowDeleteRows|nopanel=true} | | [AllowSort|SheetProtection.AllowSort] | {excerpt-include:SheetProtection.AllowSort|nopanel=true} | | [AllowUseAutoFilter|SheetProtection.AllowUseAutoFilter] | {excerpt-include:SheetProtection.AllowUseAutoFilter|nopanel=true} | | [AllowUsePivotTableReports|SheetProtection.AllowUsePivotTableReports] | {excerpt-include:SheetProtection.AllowUsePivotTableReports|nopanel=true} |
Properties

Name

Description

AllowSelectLockedCells

Excerpt Include
SheetProtection.AllowSelectLockedCells
SheetProtection.AllowSelectLockedCells
nopaneltrue

AllowSelectUnlockedCells

Excerpt Include
SheetProtection.AllowSelectUnlockedCells
SheetProtection.AllowSelectUnlockedCells
nopaneltrue

AllowFormatCells

Excerpt Include
SheetProtection.AllowFormatCells
SheetProtection.AllowFormatCells
nopaneltrue

AllowFormatRows

Excerpt Include
SheetProtection.AllowFormatRows
SheetProtection.AllowFormatRows
nopaneltrue

AllowFormatColumns

Excerpt Include
SheetProtection.AllowFormatColumns
SheetProtection.AllowFormatColumns
nopaneltrue

AllowInsertColumns

Excerpt Include
SheetProtection.AllowInsertColumns
SheetProtection.AllowInsertColumns
nopaneltrue

AllowInsertRows

Excerpt Include
SheetProtection.AllowInsertRows
SheetProtection.AllowInsertRows
nopaneltrue

AllowInsertHyperlinks

Excerpt Include
SheetProtection.AllowInsertHyperlinks
SheetProtection.AllowInsertHyperlinks
nopaneltrue

AllowDeleteColumns

Excerpt Include
SheetProtection.AllowDeleteColumns
SheetProtection.AllowDeleteColumns
nopaneltrue

AllowDeleteRows

Excerpt Include
SheetProtection.AllowDeleteRows
SheetProtection.AllowDeleteRows
nopaneltrue

AllowSort

Excerpt Include
SheetProtection.AllowSort
SheetProtection.AllowSort
nopaneltrue

AllowUseAutoFilter

Excerpt Include
SheetProtection.AllowUseAutoFilter
SheetProtection.AllowUseAutoFilter
nopaneltrue

AllowUsePivotTableReports

Excerpt Include
SheetProtection.AllowUsePivotTableReports
SheetProtection.AllowUsePivotTableReports
nopaneltrue