ODS-Dateien verschlüsseln und entschlüsseln
Contents
[
Hide
]
OpenOffice.org ist eine Office-Suite mit vollem Funktionsumfang, die den Passwortschutz und die Verschlüsselung von Dateien unterstützt. Die verschlüsselte ODS-Datei kann jedoch nur von OpenOffice geöffnet werden, nachdem das Kennwort angegeben wurde. Excel kann die verschlüsselte ODS-Datei nicht öffnen und gibt möglicherweise eine Warnmeldung aus. Die Verschlüsselungsoptionen gelten im Gegensatz zu anderen Dateitypen nicht für die ODS-Datei.
Aspose.Cells ermöglicht das Verschlüsseln und Entschlüsseln der Datei ODS. Die entschlüsselte ODS-Datei kann sowohl in Excel als auch in OpenOffice geöffnet werden,
Verschlüsseln mit OpenOffice Calc
- WählenSpeichern als und Klicken Sie auf dieMit Passwort speichern Kasten.
- Drücke denSpeichern Knopf.
- Geben Sie Ihr gewünschtes Passwort in beide einGeben Sie das Passwort zum Öffnen ein undKennwort bestätigen Felder im sich öffnenden Fenster Passwort festlegen.
- Drücke denOK Schaltfläche, um die Datei zu speichern.
ODS-Datei verschlüsseln/entschlüsseln:
Um eine ODS-Datei zu verschlüsseln, laden Sie die Datei und übergeben Sie das tatsächliche Passwort anWorkbookSettings.setPassword()bevor Sie es speichern. Die verschlüsselte Ausgabedatei ODS kann nur in OpenOffice geöffnet werden. Um eine ODS-Datei zu entschlüsseln, laden Sie die Datei, indem Sie das Passwort in derLoadOptions.setPassword() . Sobald die Datei geladen ist, rufen Sie die Funktion aufWorkbook.unprotect() mit dem tatsächlichen Passwort als Argument und übergeben Sie schließlich null anWorkbook.getWorkbookSettings().setPassword().
Beispielcode:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
static String sourceDir = Utils.Get_SourceDirectory(); | |
static String outputDir = Utils.Get_OutputDirectory(); | |
public static void main(String[] args) throws Exception { | |
//Encrypt an ODS file | |
//Encrypted ODS file can only be opened in OpenOffice as Excel does not support encrypted ODS files | |
//Initialize loading options | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.ODS); | |
// Instantiate a Workbook object. | |
// Open an ODS file. | |
Workbook workbook = new Workbook(sourceDir + "sampleODSFile.ods", loadOptions); | |
//Encryption options are not effective for ODS files | |
// Password protect the file. | |
workbook.getSettings().setPassword("1234"); | |
// Save the excel file. | |
workbook.save(outputDir + "outputEncryptedODSFile.ods"); | |
//Decrypt ODS file | |
//Decrypted ODS file can be opened both in Excel and OpenOffice | |
// Set original password | |
loadOptions.setPassword("1234"); | |
// Load the encrypted ODS file with the appropriate load options | |
Workbook encrypted = new Workbook(sourceDir + "sampleEncryptedODSFile.ods", loadOptions); | |
// Unprotect the workbook | |
encrypted.unprotect("1234"); | |
// Set the password to null | |
encrypted.getSettings().setPassword(null); | |
// Save the decrypted ODS file | |
encrypted.save(outputDir + "outputDecryptedODSFile.ods"); | |
// Print message | |
System.out.println("Encryption and Decryption applied successfully on ODS file."); | |
} |