Class AbstractLowCodeProtectionProvider
Contents
[
Hide
]AbstractLowCodeProtectionProvider class
Implementation to provide protection settings
public class AbstractLowCodeProtectionProvider
Constructors
Name | Description |
---|---|
AbstractLowCodeProtectionProvider() | The default constructor. |
Methods
Name | Description |
---|---|
virtual GetOpenPassword() | Gets the password to open spread sheet file. |
virtual GetWorkbookPassword() | Gets the password to protect the workbook with specified protection type. |
virtual GetWorkbookProtectionType() | Gets the protection type to protect the workbook. |
virtual GetWorksheetPassword(string) | Gets the password to protect the specified worksheet. |
virtual GetWorksheetProtectionType(string) | Gets the protection type to protect the specified worksheet. |
virtual GetWritePassword() | Gets the password to modify spread sheet file. |
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using Aspose.Cells.LowCode;
using System;
public class LowCodeClassAbstractLowCodeProtectionProviderDemo
{
public static void Run()
{
// Create a new workbook and add test worksheets
Workbook workbook = new Workbook();
workbook.Worksheets.Add("SalesData");
workbook.Worksheets.Add("AuditReport");
// Create custom protection provider instance
var protectionProvider = new CustomProtectionProvider();
// Apply workbook protection
workbook.Protect(
protectionProvider.GetWorkbookProtectionType(),
protectionProvider.GetWorkbookPassword()
);
// Apply protection to all worksheets
foreach (Worksheet worksheet in workbook.Worksheets)
{
worksheet.Protect(
protectionProvider.GetWorksheetProtectionType(worksheet.Name),
null, // Add null for oldPassword parameter
protectionProvider.GetWorksheetPassword(worksheet.Name)
);
}
// Set file access passwords
workbook.Settings.Password = protectionProvider.GetOpenPassword();
workbook.Settings.WriteProtection.Password = protectionProvider.GetWritePassword();
// Save protected workbook
workbook.Save("AbstractLowCodeProtectionProviderDemo.xlsx");
}
}
public class CustomProtectionProvider : AbstractLowCodeProtectionProvider
{
public override string GetOpenPassword() => "SecureOpen123";
public override string GetWritePassword() => "EditPermission456";
public override string GetWorkbookPassword() => "WorkbookLock789";
public override ProtectionType GetWorkbookProtectionType() =>
ProtectionType.Windows; // Prevent window structure changes
public override string GetWorksheetPassword(string sheetName) =>
$"SheetLock_{sheetName}"; // Dynamic password per sheet
public override ProtectionType GetWorksheetProtectionType(string sheetName) =>
ProtectionType.Contents; // Protect cell contents
}
}
See Also
- namespace Aspose.Cells.LowCode
- assembly Aspose.Cells