【问题标题】:C# Remove password from password protected(encrypted) excel file using the file passwordC# 使用文件密码从受密码保护(加密)的 excel 文件中删除密码
【发布时间】:2019-01-27 22:55:49
【问题描述】:

我正在尝试打开受密码保护的 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.
}

【问题讨论】:

    标签: c# excel excel-interop aspose aspose-cells


    【解决方案1】:

    你可以使用Workbook的Unprotect方法:

    LoadOptions loadOptions = new LoadOptions();
    loadOptions.Password = password;
    
    Workbook workbook = new Workbook(filePath, loadOptions);
    workbook.Unprotect(password);
    // or workbook.Settings.Password = "";
    workbook.Save(filePath);
    

    【讨论】:

    • 这是否应用于要(通过)删除的加密文件?
    【解决方案2】:

    感谢您的回答,我注意到您的第一个建议只会取消保护工作簿结构。

    workbook.Unprotect(password);
    

    在我的情况下,我想解密一个受密码保护(加密)的实际文件

    第二个建议效果很好,谢谢!

     workbook.Settings.Password = "";
     workbook.Save(filePath);
    

    再次感谢您的帮助

    【讨论】:

      猜你喜欢
      • 2011-02-06
      • 2010-09-22
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 2012-04-15
      • 2013-02-23
      相关资源
      最近更新 更多