加密和解密Excel文件

使用Microsoft Excel

在Microsoft Excel(例如Microsoft Excel 2003)中设置文件加密设置:

  1. 工具菜单中选择选项。会出现一个对话框。
  2. 选择安全选项卡。
  3. 输入密码并点击高级
  4. 选择加密类型并确认密码。

使用Aspose.Cells对Excel文件进行加密

下面的示例显示了如何使用Aspose.Cells API对Excel文件进行加密和密码保护。

# Open an excel file.
workbook = Workbook("Book1.xls")
# Password protect the file.
workbook.getSettings().setPassword("1234")
# Save the excel file.
workbook.save("encryptedBook1.out.xlsx")

使用Aspose.Cells对Excel文件进行解密

使用Aspose.Cells API以以下代码非常轻松地打开密码保护的Excel文件并进行解密:

#Open encrypted file with password.
loadOptions = LoadOptions()
loadOptions.setPassword("password")
Workbook workbook = Workbook("Book1.xlsx", loadOptions)
#Remove password.
workbook.getSettings().setPassword(null)
#Save the file.
workbook.save("decrypted.xlsx")