[]
Provides access to the workbook write protection options.
Use this class to configure how a workbook is protected from modification, including recommending that the workbook be opened as read-only, specifying the user who has write permission, and setting a password required to modify the file. The write-protection takes effect when the workbook is opened in an Excel application.
Instances of this class are typically obtained from WriteProtection.
public class WriteProtection
Public Class WriteProtection
WriteProtection protection = workbook.WriteProtection;
protection.WriteReservedBy = "User";
protection.ReadOnlyRecommended = true;
// Get the password from user input via GetPasswordFromSecureSource().
string password = GetPasswordFromSecureSource();
protection.WritePassword = password;
string fileName = "WriteProtection.xlsx";
workbook.Save(fileName);
| Name | Description |
|---|---|
| ReadOnlyRecommended | Returns whether the Read Only Recommended option is selected. When this option is enabled, applications that open the workbook can recommend opening it in read-only mode. |
| WritePassword | Sets the protected password to modify the file. |
| WriteReserved | Indicates whether this workbook is write protected. |
| WriteReservedBy | Gets the write-reserved user name for the workbook. This property returns the write-reserved user name stored in the workbook write protection settings. |
| Name | Description |
|---|---|
| ValidatePassword(string) | Validates the specified password against the workbook write-protection password.
Use this method to check whether a password matches the password set by
WritePassword. If the workbook is not write protected,
this method returns |