Create password protected excel file using Closedxml library
2 answers
Had the same problem - needed to test the excel file without using 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 the worksheet from filling in by adding / removing / renaming) without the option to set a password, although they haven't tested this bit:
var wb = new XLWorkbook();
wb.Protect(bool LockStrucure, bool LockWindows);
links: sheet protection example
+4
source to share