用 Node.js 和 C++ 加密与解密 ODS 文件
Contents
[
Hide
]
OpenOffice.org 是一个功能齐全的办公套件,支持密码保护和文件加密。但加密的 ODS 文件只能在提供密码后由 OpenOffice 打开。Excel 不能打开加密的 ODS 文件,可能会出现警告。与其他文件类型不同,ODS 文件的加密选项不适用。
Aspose.Cells 允许你加密和解密 ODS 文件。解密的 ODS 文件可以在 Excel 和 OpenOffice 中打开。
在OpenOffice Calc中加密
- 选择另存为,并点击带密码保存框。
- 点击保存按钮。
- 在打开密码窗口中的输入打开文件的密码和确认密码字段中键入所需的密码。
- 点击确定按钮以保存文件。
用 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()字符串设置为空。
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");