[英]Reset excel workbook password programmatically using c#
Is it possible to reset/rewrite password in excel workbook using c#? 是否可以使用C#在excel工作簿中重置/重写密码?
I tried to do a couple things, but it did't solve my question: 我尝试做几件事,但是并没有解决我的问题:
1) workbook.Password = "";
1)
workbook.Password = "";
doesn't help 没有帮助
2) workbook.Protect ("",true,true);
2)
workbook.Protect ("",true,true);
workbook.Unprotect(""); doestn't help
3) I also tried to resave workbook.SaveAs(workbook.FullName,XlNormal,"","",false,null,Excel.XlSaveAsAccessMode.xlNoChange,null,false,null,null,false);
3)我也尝试重新保存
workbook.SaveAs(workbook.FullName,XlNormal,"","",false,null,Excel.XlSaveAsAccessMode.xlNoChange,null,false,null,null,false);
If you have any idea, please help. 如果您有任何想法,请帮助。
the way to go is 要走的路是
workbook.Unprotect(pwd);
But to have it work you need to pass it the correct password, ie string.Empty
is not enough. 但是要使其正常工作,您需要向其传递正确的密码,即
string.Empty
还不够。
Be careful that password protection can be put not only on workbooks, but even on the single worksheets, so it could be better to loop on the sheets and call Unprotect
on them, too. 请注意,不仅可以在工作簿上甚至在单个工作表上都可以设置密码保护,因此最好在工作表上循环并对其调用
Unprotect
。
If you don't know the password, here you can find an excel macro that can unprotect your file. 如果您不知道密码,则可以在此处找到可以取消保护文件的excel宏。 It shouldn't be too difficult to translate it into C if you really need to.
如果确实需要,将其转换为C并不难。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.