Node.js経由のC++を使用してODSファイルを暗号化および復号化する
Contents
[
Hide
]
OpenOffice.orgは、パスワード保護とファイルの暗号化をサポートするフル機能のオフィススイートです。ただし、暗号化されたODSファイルは、パスワードを提供した後にのみOpenOfficeで開くことができます。Excelは暗号化されたODSファイルを開けず、警告メッセージを表示する場合があります。暗号化オプションは他のファイルタイプとは異なり、ODSファイルには適用されません。
Aspose.Cellsを使用すれば、ODSファイルの暗号化と復号化が可能です。復号化されたODSファイルはExcelとOpenOfficeの両方で開くことができます。
OpenOffice Calcで暗号化
- 名前を付けて保存を選択し、パスワードを設定して保存ボックスをクリックします。
- 保存ボタンをクリックします。
- 開いた「パスワードの設定」ウィンドウの「開くためのパスワードを入力」および「パスワードを確認」フィールドに希望するパスワードを入力します。
- ファイルを保存するために OK ボタンをクリックします。
Aspose.Cells for Node.js via C++を用いてODSファイルを暗号化する
ODSファイルを暗号化するには、ファイルを読み込み、WorkbookSettings.getPassword()の値を実際のパスワードに設定して保存します。出力される暗号化されたODSファイルはOpenOfficeでのみ開くことができます。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const sourceDir = path.join(__dirname, "source");
const outputDir = path.join(__dirname, "output");
// Open an ODS file
const workbook = new AsposeCells.Workbook(path.join(sourceDir, "sampleODSFile.ods"));
// Password protect the file
workbook.getSettings().setPassword("1234");
// Save the ODS file
workbook.save(path.join(outputDir, "outputEncryptedODSFile.ods"));
Aspose.Cells for Node.js via C++を用いてODSファイルを復号化する
ODSファイルを復号化するには、LoadOptions.getPassword()にパスワードを入力してファイルを読み込みます。ファイルが読み込まれたら、WorkbookSettings.getPassword()の文字列をnullに設定してください。
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const sourceDir = path.join(__dirname, "data");
// Output directory
const outputDir = path.join(__dirname, "output");
// Open an encrypted ODS file
const loadOptions = new AsposeCells.LoadOptions(AsposeCells.LoadFormat.Ods);
// Set original password
loadOptions.setPassword("1234");
// Load the encrypted ODS file with the appropriate load options
const workbook = new AsposeCells.Workbook(path.join(sourceDir, "sampleEncryptedODSFile.ods"), loadOptions);
// Set the password to null
workbook.getSettings().setPassword(null);
// Save the decrypted ODS file
workbook.save(outputDir + "outputDecryptedODSFile.ods");