Зашифровать и расшифровать ODS файлов
Contents
[
Hide
]
OpenOffice.org — полнофункциональный офисный пакет, поддерживающий защиту паролем и шифрование файлов. Однако зашифрованный файл ODS может быть открыт только OpenOffice после ввода пароля. Excel не может открыть зашифрованный файл ODS и может вывести предупреждающее сообщение. Параметры шифрования неприменимы к файлу ODS, в отличие от других типов файлов.
Aspose.Cells позволяет зашифровать и расшифровать файл ODS. Расшифрованный файл ODS можно открыть как в Excel, так и в OpenOffice,
Шифрование с помощью OpenOffice Calc
- ВыбиратьСохранить как и щелкнитеСохранить с паролем коробка.
- Нажмите наСохранять кнопка.
- Введите желаемый пароль в обаВведите пароль для открытия иПодтвердите пароль поля в открывшемся окне Установить пароль.
- Нажмите наХОРОШО кнопку для сохранения файла.
Шифрование/дешифрование ODS Файл:
Для шифрования файла ODS загрузите файл и передайте фактический парольWorkbookSettings.setPassword()перед сохранением. Выходной зашифрованный файл ODS можно открыть только в OpenOffice. Для расшифровки файла ODS загрузите файл, указав пароль вLoadOptions.setPassword() . После загрузки файла вызовите функциюРабочая книга.unprotect() с фактическим паролем в качестве аргумента и, наконец, передать null вРабочая книга.getWorkbookSettings().setPassword().
Образец кода:
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."); | |
} |