Crittografare e decrittografare i file ODS
Contents
[
Hide
]
OpenOffice.org è una suite per ufficio completa che supporta la protezione tramite password e la crittografia dei file. Tuttavia, il file ODS crittografato può essere aperto solo da OpenOffice dopo aver fornito la password. Excel non è in grado di aprire il file crittografato ODS e potrebbe generare un messaggio di avviso. Le opzioni di crittografia non sono applicabili per il file ODS a differenza di altri tipi di file.
Aspose.Cells consente di crittografare e decrittografare il file ODS. Il file ODS decifrato può essere aperto sia in Excel che in OpenOffice,
Crittografare con OpenOffice Calc
- SelezionareSalva come e fare clic suSalva con password scatola.
- Clicca ilSalva pulsante.
- Digita la password desiderata in entrambi i fileInserisci la password per aprire eConferma password campi nella finestra Imposta password che si apre.
- Clicca ilOK pulsante per salvare il file.
Crittografia/Decrittografia ODS File:
Per crittografare un file ODS, caricare il file e passare la password effettiva aWorkbookSettings.setPassword()prima di salvarlo. Il file crittografato di output ODS può essere aperto solo in OpenOffice. Per decrittografare un file ODS, caricare il file fornendo la password nel fileLoadOptions.setPassword() . Una volta caricato il file, chiama functionCartella di lavoro.unprotect() con la password effettiva come argomento e infine passare null aWorkbook.getWorkbookSettings().setPassword().
Codice d’esempio:
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."); | |
} |