Ashish Singla
Ashish Singla

Reputation: 61

Create password protected excel file using Closedxml library

I am new in c# asp.net and I tried to create XLS file using third party library "Closedxml". Now I also want to protect the XLS file with password how I can achieve this.

Your help would be appreciable. Thanks in advance Ashish

Upvotes: 6

Views: 11533

Answers (2)

Cerveser
Cerveser

Reputation: 860

To protect the file with a password is not possible in ClosedXML, see github

Upvotes: 3

JesseZ
JesseZ

Reputation: 91

Had the same issue - needed to protext an excel file without using the interop libraries.

With ClosedXML you can password protect at the worksheet level: 
var ws = wb.Worksheets.Add("someworksheet");
ws.Protect("123");  // 123 will be the password

And it looks like you can lock the structure of the workbook (prevent worksheet add/delete/rename) without the option of setting a password, although have not tested this bit extensively:

var wb = new XLWorkbook();
wb.Protect(bool LockStrucure, bool LockWindows); 

references: sheet protection example

Upvotes: 7

Related Questions