Worksheet.Protect
Contents
[
Hide
]Protect(ProtectionType)
Protects worksheet.
public void Protect(ProtectionType type)
Parameter | Type | Description |
---|---|---|
type | ProtectionType | Protection type. |
Remarks
This method protects worksheet without password. It can protect worksheet in all versions of Excel file.
Examples
using System;
using Aspose.Cells;
namespace AsposeCellsExamples
{
public class WorksheetMethodProtectWithProtectionTypeDemo
{
public static void Run()
{
// Create a new workbook
Workbook workbook = new Workbook();
// Access the first worksheet
Worksheet sheet = workbook.Worksheets[0];
// Protect the worksheet with Objects protection type
sheet.Protect(ProtectionType.Objects);
// Save the workbook
workbook.Save("ProtectedWorksheet.xlsx");
}
}
}
See Also
- enum ProtectionType
- class Worksheet
- namespace Aspose.Cells
- assembly Aspose.Cells
Protect(ProtectionType, string, string)
Protects worksheet.
public void Protect(ProtectionType type, string password, string oldPassword)
Parameter | Type | Description |
---|---|---|
type | ProtectionType | Protection type. |
password | String | Password. |
oldPassword | String | If the worksheet is already protected by a password, please supply the old password. Otherwise, you can set a null value or blank string to this parameter. |
Remarks
This method can protect worksheet in all versions of Excel file.
Examples
using System;
using Aspose.Cells;
namespace AsposeCellsExamples
{
public class WorksheetMethodProtectWithProtectionTypeStringStringDemo
{
public static void Run()
{
// Create a new workbook
Workbook workbook = new Workbook();
// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Protect the worksheet with password and allow all protection types
worksheet.Protect(ProtectionType.All, "password123", null);
// Save the workbook
workbook.Save("ProtectedWorksheet.xlsx");
}
}
}
See Also
- enum ProtectionType
- class Worksheet
- namespace Aspose.Cells
- assembly Aspose.Cells