Back to Devexpress

IWorkbook.Protect(String, Boolean, Boolean) Method

officefileapi-devexpress-dot-spreadsheet-dot-iworkbook-dot-protect-x28-system-dot-string-system-dot-boolean-system-dot-boolean-x29.md

latest4.2 KB
Original Source

IWorkbook.Protect(String, Boolean, Boolean) Method

Protects the structure and windows of a workbook.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void Protect(
    string password,
    bool lockStructure,
    bool lockWindows
)
vb
Sub Protect(
    password As String,
    lockStructure As Boolean,
    lockWindows As Boolean
)

Parameters

NameTypeDescription
passwordString

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.

|

Remarks

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.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Protect(String, Boolean, Boolean) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_API_Part02/SpreadsheetActions/ProtectionActions.cs#L24

csharp
if (!workbook.IsProtected)
    workbook.Protect("password", true, false);
workbook.Worksheets[0].Visible = false;

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/ProtectionActions.cs#L22

csharp
if (!workbook.IsProtected)
    workbook.Protect("password", true, false);
workbook.Worksheets[0].Visible = false;

winforms-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_API_Part02/SpreadsheetActions/ProtectionActions.vb#L27

vb
If Not workbook.IsProtected Then
    workbook.Protect("password", True, False)
End If

wpf-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/ProtectionActions.vb#L25

vb
If Not workbook.IsProtected Then
    workbook.Protect("password", True, False)
End If

See Also

IWorkbook Interface

IWorkbook Members

DevExpress.Spreadsheet Namespace