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.

C# NuGet Library for Excel

Install with NuGet

Install-Package IronXL.Excel
C# Excel DLL

Download DLL

Download DLL

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, workSheet.ProtectSheet("IronXL").

using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set protection for selected worksheet

Imports IronXL

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

' Set protection for selected worksheet

VB   C#

Open Password Protected Worksheet

Access Protected Worksheet

Removing Password from Worksheet

Use UnprotectSheet method to remove any password from a particular worksheet like so workSheet.UnprotectSheet().

// Remove protection for selected worksheet. It works without password!
' Remove protection for selected worksheet. It works without password!
VB   C#

IronXL allows you to Protect and Unprotect any Excel WorkBook and WorkSheet with a single line of C# code.