How to Set Password to Worksheet
Restrict a ReadOnly authentication is a very common required to data files. IronXL makes applying ReadOnly protection to worksheets very easy.
How to Password Protect Worksheet
- Download C# library to password protect worksheets
- Access the password protected worksheet in opened workbook
- Apply password protection to selected worksheet
- Remove password protection of selected worksheet
- Export spreadsheet to different spreadsheet formats
Install with NuGet
Manually install into your project
Accessing Password Protected Worksheet
IronXL can access and modify any protected worksheet without requiring the password. As long as the spreadsheet is opened with IronXL, any cell in any worksheet can be modified.
Applying Password to Worksheet
Set password to worksheet will act as a ReadOnly authentication to that worksheet, because it is possible to view the worksheet's content in Excel but not modify it. Use
ProtectSheet method with a password as parameter to protect the selected worksheet. For example,
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 Password Protected Worksheet
Removing Password from Worksheet
UnprotectSheet method to remove any password from a particular worksheet like so
// 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.