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.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Access 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()
$vbLabelText   $csharpLabel

Open a Password-Protected Worksheet

Access 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()
$vbLabelText   $csharpLabel

IronXL allows you to protect and unprotect any Excel workbook and worksheet with a single line of C# code.

Frequently Asked Questions

How can I password protect an Excel worksheet in C#?

To password protect an Excel worksheet, use IronXL's `ProtectSheet` method with a password as a parameter. For example, `workSheet.ProtectSheet("IronXL")`.

How do I access a password-protected worksheet in C#?

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.

How can I remove a password from a worksheet in C#?

To remove a password from a specific worksheet using IronXL, use the `UnprotectSheet` method. Call `workSheet.UnprotectSheet()` to remove any password associated with the worksheet.

What is the first step to password protect worksheets in C#?

The first step is to download the IronXL C# library to enable password protection for worksheets. You can get it from NuGet.

Can a protected worksheet be modified in C#?

Yes, IronXL allows you to access and modify any protected worksheet without needing the password, once the spreadsheet is opened.

What method is used to save changes after protecting a worksheet in C#?

After applying protection using IronXL, use the `SaveAs` method to save the changes to the workbook, for example, `workbook.SaveAs("protected_example.xlsx")`.

Is it possible to export the spreadsheet to different formats in C#?

Yes, IronXL allows you to export the spreadsheet to different formats after applying or removing password protection.

How is read-only authentication for worksheets handled in C#?

IronXL makes it easy to apply read-only protection to worksheets by using the `ProtectSheet` method with a password, allowing users to view content but restrict modifications.

What is required to begin using worksheet protection in C#?

To begin using IronXL for worksheet protection, you need to download the library and reference it in your C# project.

Chaknith related to Remove Password from Worksheet
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.