How to Set a Password to Workbook

by Chaknith Bin

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.




C# NuGet Library for Excel

Install with NuGet

Install-Package IronXL.Excel
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for Excel

Install with NuGet

Install-Package IronXL.Excel
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

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

First Step:
green arrow pointer

Check out IronXL on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming Excel with C#.

C# NuGet Library for Excel nuget.org/packages/IronXL.Excel/
Install-Package IronXL.Excel

Consider installing the IronXL DLL directly. Download and manually install it for your project or GAC form: IronXL.zip

Dll Img related to How to Set a Password to Workbook

Manually install into your project

Download DLL

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.

: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()
VB   C#

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
VB   C#

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

Chaknith related to Remove Password from Workbook

Chaknith Bin

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.