ODSファイルの暗号化と複合化
Contents
[
Hide
]
OpenOffice.orgはパスワード保護とファイルの暗号化をサポートする完全な機能を備えたオフィススイートです。ただし、暗号化されたODSファイルはパスワードを提供した後にのみOpenOfficeで開くことができ、Excelは暗号化されたODSファイルを開くことはできません。暗号化オプションは、その他のファイルタイプとは異なり、ODSファイルには適用されません。
Aspose.Cellsを使用して、ODSファイルの暗号化と複合化が可能です。複合されたODSファイルはExcelとOpenOfficeの両方で開くことができます。
OpenOffice Calcで暗号化
- 「名前を付けて保存」を選択し、「パスワードで保存」ボックスをクリックします。
- 保存ボタンをクリックします。
- 開いた「パスワードの設定」ウィンドウの「開くためのパスワードを入力」および「パスワードを確認」フィールドに希望するパスワードを入力します。
- ファイルを保存するために OK ボタンをクリックします。
ODSファイルの暗号化/復号化:
ODSファイルを暗号化するには、ファイルを読み込み、保存する前に実際のパスワードを WorkbookSettings.setPassword() に渡します。出力される暗号化されたODSファイルはOpenOfficeでのみ開くことができます。ODSファイルを復号化するには、LoadOptions.setPassword() にパスワードを提供してファイルを読み込みます。ファイルを読み込んだ後は、実際のパスワードを引数として関数 Workbook.unprotect() を呼び出し、最後に Workbook.getWorkbookSettings().setPassword() にnullを渡します。
サンプルコード:
This file contains 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."); | |
} |