How to Set Password to Worksheet
Restricting a worksheet with a Read-Only authentication is a very common requirement for data files. IronXL makes it easy to apply Read-Only protection to worksheets in .NET.
How to Password Protect Worksheets
- Download the C# library to password protect worksheets
- Access the password-protected worksheet in the opened workbook
- Apply password protection to the selected worksheet
- Remove password protection from the selected worksheet
- Export the spreadsheet to different spreadsheet formats
Install with NuGet
Install-Package IronXL.Excel
Download DLL
Manually install into your project
Install with NuGet
Install-Package IronXL.Excel
Download DLL
Manually install into your project
Start using IronPDF in your project today with a free trial.
Check out IronXL on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming Excel with C#.
Install-Package IronXL.Excel
Consider installing the IronXL DLL directly. Download and manually install it for your project or GAC form: IronXL.zip
Manually install into your project
Download DLLAccess a Password Protected Worksheet
IronXL allows you to access and modify any protected worksheet without requiring the password. Once the spreadsheet is opened with IronXL, you can modify any cell in any worksheet.
Apply Password to Worksheet
To restrict modifications to a worksheet while allowing users to view its content in Excel, use the ProtectSheet
method with a password as a parameter. For example, workSheet.ProtectSheet("IronXL")
. This sets a password-based ReadOnly authentication for the selected worksheet.
:path=/static-assets/excel/content-code-examples/how-to/set-password-worksheet-protect.cs
using IronXL;
WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Set protection for selected worksheet
workSheet.ProtectSheet("IronXL");
workBook.Save();
Imports IronXL
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Set protection for selected worksheet
workSheet.ProtectSheet("IronXL")
workBook.Save()
Open a Password-Protected Worksheet
Remove Password from Worksheet
To remove a password from a specific worksheet, you can use the UnprotectSheet
method. Simply call workSheet.UnprotectSheet()
to remove any password associated with the worksheet.
:path=/static-assets/excel/content-code-examples/how-to/set-password-worksheet-unprotect.cs
// Remove protection for selected worksheet. It works without password!
workSheet.UnprotectSheet();
' Remove protection for selected worksheet. It works without password!
workSheet.UnprotectSheet()
IronXL allows you to protect and unprotect any Excel workbook and worksheet with a single line of C# code.