Excel Dateien verschlüsseln und entschlüsseln

Verwendung von Microsoft Excel

Um die Dateiverschlüsselungseinstellungen in Microsoft Excel festzulegen (hier Microsoft Excel 2003):

  1. Wählen Sie im Menü Extras die Option Optionen aus. Es wird ein Dialogfeld angezeigt.
  2. Wählen Sie den Tab Sicherheit aus.
  3. Geben Sie ein Passwort ein und klicken Sie auf Erweitert
  4. Wählen Sie den Verschlüsselungstyp aus und bestätigen Sie das Passwort.

Excel-Datei mit Aspose.Cells verschlüsseln

Das folgende Beispiel zeigt, wie Sie mit dem Aspose.Cells-API eine Excel-Datei verschlüsseln und kennwortgeschützt machen können.

// 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");

Passwort zum Ändern der Option festlegen

Das folgende Beispiel zeigt, wie Sie die Passwort zum Ändern Microsoft Excel-Option für eine vorhandene Datei mithilfe der Aspose.Cells-API festlegen.

// 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");

Entschlüsselung einer Excel-Datei mit Aspose.Cells

Es ist sehr einfach, eine passwortgeschützte Excel-Datei zu öffnen und mit den folgenden Codes zu entschlüsseln, die Aspose.Cells-API zu verwenden:

//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");

Erweiterte Themen