Excel ファイルの暗号化と復号化

MS Excel の使用

MS Excel (MS Excel 2003 など) でファイル暗号化設定を実装するには、次のことを試してください。

  • からツールメニュー、選択オプションを選択し、安全タブ。
  • 入力開くためのパスワードをクリックし、高度ボタン。
  • 暗号化タイプを選択し、パスワードを確認します。

todo:画像_代替_文章

図: [オプション] ダイアログ

todo:画像_代替_文章

図: [暗号化の種類] ダイアログ

Excelファイルの暗号化

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

サンプルコード:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(EncryptingFiles.class) + "loading_saving/";
// Instantiate a Workbook object by excel file path
Workbook workbook = new Workbook(dataDir + "Book1.xls");
// Password protect the file.
workbook.getSettings().setPassword("1234");
// Specify XOR encrption type.
workbook.setEncryptionOptions(EncryptionType.XOR, 40);
// Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic
// Provider).
workbook.setEncryptionOptions(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128);
// Save the excel file.
workbook.save(dataDir + "EncryptingFiles_out.xls");
// Print message
System.out.println("Encryption applied successfully on output file.");

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

パスワードで保護された Excel ファイルを開き、次のコードとして Aspose.Cells API を使用して復号化するのは非常に困難です。

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