How to Set a Password to Workbook

Ensuring that information or data is shared with the correct individual is crucial for maintaining proper authority. With IronXL, you can create password-protected spreadsheets and secure each individual worksheet.


Get started with IronXL

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

First Step:
green arrow pointer

Access a Password-Protected Workbook

A protected spreadsheet can be opened by providing the password as the second parameter to the Load method. For example: WorkBook.Load("sample.xlsx", "IronSoftware").

Please note
It is not possible to open a protected spreadsheet without the correct password

Apply a Password to Workbook

To password-protect a spreadsheet, use the Encrypt method as shown in the code below:

:path=/static-assets/excel/content-code-examples/how-to/set-password-workbook-protect.cs
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Open protected spreadsheet file
WorkBook protectedWorkBook = WorkBook.Load("sample.xlsx", "IronSoftware");

// Set protection for spreadsheet file
workBook.Encrypt("IronSoftware");

workBook.Save();
Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")

' Open protected spreadsheet file
Dim protectedWorkBook As WorkBook = WorkBook.Load("sample.xlsx", "IronSoftware")

' Set protection for spreadsheet file
workBook.Encrypt("IronSoftware")

workBook.Save()
$vbLabelText   $csharpLabel

Open a Password-Protected Workbook

Open Protected Spreadsheet

Remove Password from Workbook

To remove the password from a spreadsheet, simply set the Password field to null, as demonstrated in the code below:

Please note
This action can only be performed after accessing the workbook. Therefore, it is necessary to know the original password.

:path=/static-assets/excel/content-code-examples/how-to/set-password-workbook-unprotect.cs
// Remove protection for opened workbook. Original password is required.
workBook.Password = null;
' Remove protection for opened workbook. Original password is required.
workBook.Password = Nothing
$vbLabelText   $csharpLabel

IronXL provides the ability to protect and unprotect Excel workBooks and workSheets with a single line of C# code.

Frequently Asked Questions

How do I set a password to an Excel workbook?

To set a password to an Excel workbook using IronXL, load the workbook with IronXL.WorkBook.Load, use the Encrypt method with your desired password, and save the changes.

How can I access a password-protected workbook?

You can access a password-protected workbook by providing the password as the second parameter to the WorkBook.Load method in IronXL.

What is the method to remove a password from an Excel workbook?

To remove a password from an Excel workbook, load the protected workbook with the original password, then set the Password field to null using the Decrypt method in IronXL, and save the workbook.

Is it possible to open a password-protected spreadsheet without the correct password?

No, it is not possible to open a password-protected spreadsheet without the correct password using IronXL.

Where can I download the library for password-protecting workbooks?

You can download the IronXL library for password-protecting workbooks from the NuGet website at https://nuget.org/packages/IronXL.Excel/.

Can it be used to protect individual worksheets in addition to workbooks?

Yes, IronXL can be used to protect and unprotect both Excel workbooks and worksheets using C# code.

Chaknith related to Remove Password from Workbook
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.