用 Node.js 和 C++ 加密与解密 ODS 文件

在OpenOffice Calc中加密

  1. 选择另存为,并点击带密码保存框。
  2. 点击保存按钮。
  3. 在打开密码窗口中的输入打开文件的密码确认密码字段中键入所需的密码。
  4. 点击确定按钮以保存文件。

用 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");