Back to Devexpress

WriteProtectionOptions.SetPassword(String) Method

officefileapi-devexpress-dot-spreadsheet-dot-writeprotectionoptions-dot-setpassword-x28-system-dot-string-x29.md

latest2.5 KB
Original Source

WriteProtectionOptions.SetPassword(String) Method

Specifies the password used to modify a workbook.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void SetPassword(
    string password
)
vb
Sub SetPassword(
    password As String
)

Parameters

NameTypeDescription
passwordString

The password used to write-protect the document.

|

Remarks

The following example demonstrates how to write-protect a workbook:

csharp
using(var workbook = new Workbook()) {
    var wpOptions = workbook.DocumentSettings.WriteProtection;
    wpOptions.SetPassword("Password");
    wpOptions.UserName = "John Smith";
    workbook.SaveDocument("WriteProtectedDocument.xlsx");
}
vb
Using workbook As New Workbook()
    Dim wpOptions As WriteProtectionOptions = workbook.DocumentSettings.WriteProtection
    wpOptions.SetPassword("Password")
    wpOptions.UserName = "John Smith"
    workbook.SaveDocument("WriteProtectedDocument.xlsx")
End Using

When users open this workbook in Microsoft® Excel®, it prompts them to enter a password to modify the document.

Note

Write-protection options are ignored when you open a document in the WinForms or WPF Spreadsheet control. You can handle the SpreadsheetControl.DocumentLoaded event to check whether the document is write-protected (or its ReadOnlyRecommended option is enabled). If true , activate the control’s ReadOnly property.

See Also

WriteProtectionOptions Interface

WriteProtectionOptions Members

DevExpress.Spreadsheet Namespace