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

Microsoft エクセルを使う

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

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

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

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object.
// Open an excel file.
Workbook workbook = new Workbook(dataDir + "Book1.xls");
// Specify XOR encryption type.
workbook.SetEncryptionOptions(EncryptionType.XOR, 40);
// Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider).
workbook.SetEncryptionOptions(EncryptionType.StrongCryptographicProvider, 128);
// Password protect the file.
workbook.Settings.Password = "1234";
// Save the excel file.
workbook.Save(dataDir + "encryptedBook1.out.xls");

オプションを変更するためのパスワードの指定

次の例は、変更するパスワード Microsoft Aspose.Cells API を使用した既存ファイルの Excel オプション。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object.
// Open an excel file.
Workbook workbook = new Workbook(dataDir + "Book1.xls");
// Set the password for modification.
workbook.Settings.WriteProtection.Password = "1234";
// Save the excel file.
workbook.Save(dataDir + "SpecifyPasswordToModifyOption.out.xls");

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

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

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

先行トピック