使用Closedxml库创建受密码保护的Excel文件 [英] Create password protected excel file using Closedxml library
问题描述
我是c#asp.net的新手,我尝试使用第三方库 Closedxml创建XLS文件。现在,我也想用密码保护XLS文件,以实现该目的。
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.
您的帮助将不胜枚举。
预先感谢
Ashish
Your help would be appreciable. Thanks in advance Ashish
推荐答案
存在相同的问题-需要在不使用的情况下生成excel文件
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);
引用:
工作表保护示例
这篇关于使用Closedxml库创建受密码保护的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!