在使用Node.js通过C++为已签名的Excel文件添加数字签名

可能的使用场景

Aspose.Cells for Node.js via C++提供了Workbook.addDigitalSignature(digitalSignatureCollection)方法,可以用来为已签名的Excel文件添加数字签名。

如何向已经签名的Excel文件添加数字签名

以下示例代码演示了如何使用Workbook.addDigitalSignature(digitalSignatureCollection)方法为已签名的Excel文件添加数字签名。请查看此代码使用的示例Excel文件,该文件已进行数字签名。然后查看由代码生成的输出Excel文件。在此代码中使用了名为AsposeDemo.pfx的演示证书,密码为aspose。截图显示了示例代码执行后对示例Excel文件的效果。

todo:image_alt_text

示例代码

const AsposeCells = require("aspose.cells.node");
const path = require("path");

const dataDir = path.join(__dirname, "data");
// Certificate file path and password
const certFileName = path.join(dataDir, "AsposeDemo.pfx");
const password = "aspose";

// Load the workbook which is already digitally signed to add new digital signature
const workbook = new AsposeCells.Workbook(path.join(dataDir, "sampleDigitallySignedByCells.xlsx"));

// Create the digital signature collection
const dsCollection = new AsposeCells.DigitalSignatureCollection();


// Create new digital signature and add it in digital signature collection
const signature = new AsposeCells.DigitalSignature(certFileName, password, "Aspose.Cells added new digital signature in existing digitally signed workbook.", new Date());
dsCollection.add(signature);

// Add digital signature collection inside the workbook
workbook.addDigitalSignature(dsCollection);

// Save the workbook and dispose of it.
workbook.save(path.join(__dirname, "outputDigitallySignedByCells.xlsx"));
workbook.dispose();