[英]C# Remove password from password protected(encrypted) excel file using the file password
我试图打开一个受密码保护的Excel文件(版本xls,xlsx,xlsm)。 我需要打开文件并从每个文件中删除密码。 我拥有要处理的文件的所有密码。
我无法使用Microsoft Interop Excel,因为必须在服务器上安装excel才能使其正常工作。 我已经在使用Aspose.Cells打开不受密码保护的文件。 但是我希望能够保存文件而不用密码覆盖它。
有什么建议吗? 提前致谢
到目前为止的代码
public static void RemovePassword(string filePath, string password){
LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = password;
Workbook src = new Workbook(filePath, loadOptions);
//need a way of removing the password from the file.
}
您可以使用工作簿的取消保护方法:
LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = password;
Workbook workbook = new Workbook(filePath, loadOptions);
workbook.Unprotect(password);
// or workbook.Settings.Password = "";
workbook.Save(filePath);
感谢您的回答,我注意到您的第一个建议只会保护工作簿结构。
workbook.Unprotect(password);
以我为例,我想解密受密码保护的实际文件(已加密)
第二个建议非常感谢!
workbook.Settings.Password = "";
workbook.Save(filePath);
再次感谢你的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.