Class WriteProtection
WriteProtection class
Specifies write protection settings for a workbook.
public class WriteProtection
Constructors
Properties
Name | Description |
---|
Author { get; set; } | Gets and sets the author. |
IsWriteProtected { get; } | Indicates whether this workbook is write protected. |
Password { get; set; } | Sets the protected password to modify the file. |
RecommendReadOnly { get; set; } | Indicates if the Read Only Recommended option is selected. |
Methods
Name | Description |
---|
ValidatePassword(string) | Returns true if the specified password is the same as the write-protection password the file was protected with. |
Examples
[C#]
namespace Demos
{
using Aspose.Cells;
using System;
public class WriteProtectionDemo
{
public static void WriteProtectionExample()
{
// Create a new workbook
Workbook workbook = new Workbook();
// Access the workbook's settings
WorkbookSettings settings = workbook.Settings;
// Access the write protection settings
WriteProtection writeProtection = settings.WriteProtection;
// Set the author of the write protection
writeProtection.Author = "John Doe";
// Set the password for write protection
writeProtection.Password = "password123";
// Set the recommend read-only option
writeProtection.RecommendReadOnly = true;
// Check if the workbook is write protected
bool isWriteProtected = writeProtection.IsWriteProtected;
Console.WriteLine("Is Write Protected: " + isWriteProtected);
// Validate the password
bool isValidPassword = writeProtection.ValidatePassword("password123");
Console.WriteLine("Is Valid Password: " + isValidPassword);
// Save the workbook
workbook.Save("WriteProtectionExample.xlsx");
return;
}
}
}
See Also