Excel Dateien verschlüsseln und entschlüsseln
Verwendung von MS Excel
In MS Excel (z. B. MS Excel 2003) können Sie versuchen, Dateiverschlüsselungseinstellungen zu implementieren:
- Wählen Sie im Extras-Menü Optionen und dann die Registerkarte Sicherheit.
- Geben Sie Kennwort zum Öffnen ein und klicken Sie auf die Schaltfläche Erweitert.
- Wählen Sie den Verschlüsselungstyp und bestätigen Sie das Kennwort.
Abbildung: Optionsdialog
Abbildung: Dialogfeld Verschlüsselungstyp
Verschlüsselung einer Excel-Datei
Das folgende Beispiel zeigt, wie Sie eine Excel-Datei mithilfe der Aspose.Cells-API verschlüsseln/passwortgeschützt machen können.
Beispielcode:
// 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."); |
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.setPassword("password"); | |
Workbook workbook = new Workbook("Book1.xlsx", loadOptions); | |
//Remove password. | |
workbook.getSettings().setPassword(null); | |
//Save the file. | |
workbook.save("Book1.xlsx"); |