.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Workbook.Protect(String, Boolean, Boolean) Method

Protects the structure and windows of a workbook.

You need an active license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this method in production code.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Docs.v20.1.dll


public void Protect(
    string password,
    bool lockStructure,
    bool lockWindows
Public Sub Protect(
    password As String,
    lockStructure As Boolean,
    lockWindows As Boolean


Name Type Description
password String

A string that specifies a password for the workbook. If an empty string is specified, the workbook can be unprotected without a password.

lockStructure Boolean

true, to lock the structure of the workbook (the position of the sheets); otherwise, false.

lockWindows Boolean

true, to prevent users from changing the position of worksheet windows; otherwise, false.


Locked structure of the workbook prevents users from adding or deleting worksheets, from hiding worksheets or displaying hidden worksheets. Locked windows option prevents users from freezing or unfreezing panes.

If the workbook is already protected (the Workbook.IsProtected property is true), the Protect method raises an exception.

' Protect workbook structure (prevents users from adding or deleting worksheets
' or from displaying hidden worksheets).
If Not workbook.IsProtected Then
    workbook.Protect("password", True, False)
End If
workbook.Worksheets(0).Visible = False
Dim worksheet As Worksheet = workbook.Worksheets(1)
worksheet("D5").Value = "You are not allowed to add or delete a worksheet."
worksheet("D6").Value = "Hidden worksheets cannot be displayed."
See Also