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
ClosedXML is a . NET library for reading, manipulating and writing Excel 2007+ (. xlsx, . xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With