Excelファイルの暗号化および復号化

Microsoft Excel の使用

Microsoft Excel(ここではMicrosoft Excel 2003)でファイルの暗号化設定を行うには:

  1. ツールメニューからオプションを選択します。ダイアログが表示されます。
  2. セキュリティタブを選択します。
  3. パスワードを入力し、詳細をクリックします。
  4. 暗号化方式を選択し、パスワードを確認します。

Aspose.CellsでExcelファイルを暗号化

この例は、Aspose.Cells for Python via .NET APIを使用してExcelファイルを暗号化し、パスワード保護する方法を示しています。

from aspose.cells import EncryptionType, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a Workbook object.
# Open an excel file.
workbook = Workbook(dataDir + "Book1.xls")
# Specify XOR encryption type.
workbook.set_encryption_options(EncryptionType.XOR, 40)
# Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider).
workbook.set_encryption_options(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128)
# Password protect the file.
workbook.settings.password = "1234"
# Save the excel file.
workbook.save(dataDir + "encryptedBook1.out.xls")

修正パスワードを指定するオプション

この例は、既存のファイルに対してAspose.Cells for Python via .NETを使って変更パスワードを設定する方法を示しています。

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a Workbook object.
# Open an excel file.
workbook = Workbook(dataDir + "Book1.xls")
# Set the password for modification.
workbook.settings.write_protection.password = "1234"
# Save the excel file.
workbook.save(dataDir + "SpecifyPasswordToModifyOption.out.xls")

Aspose.CellsでExcelファイルを復号化

パスワード保護されたエクセルファイルを開き、次のコードのようにAspose.Cells for Python via .NET APIを使用して復号化するのは非常に簡単です:

from aspose.cells import LoadOptions, Workbook
# Open encrypted file with password.
loadOptions = LoadOptions()
loadOptions.password = "password"
workbook = Workbook("Book1.xlsx", loadOptions)
# Remove password.
workbook.settings.password = None
# Save the file.
workbook.save("Book1.xlsx")

高度なトピック