将数字签名添加到已签名的 Excel 文件

可能的使用场景

Aspose.Cells 提供了Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)可用于将数字签名添加到已签名的 Excel 文件的方法。

将数字签名添加到已签名的 Excel 文件

下面的示例代码演示了如何使用Workbook.AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)向已签名的 Excel 文件添加数字签名的方法。请检查示例 Excel 文件在这段代码中使用。此文件已经过数字签名。请检查输出Excel文件由代码生成。我们使用了名为AsposeDemo.pfx在这个有密码的代码中提出.截图显示了示例代码在示例Excel文件上执行后的效果。

待办事项:图片_替代_文本

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Certificate file and its password
string certFileName = sourceDir + "AsposeDemo.pfx";
string password = "aspose";
//Load the workbook which is already digitally signed to add new digital signature
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(sourceDir + "sampleDigitallySignedByCells.xlsx");
//Create the digital signature collection
Aspose.Cells.DigitalSignatures.DigitalSignatureCollection dsCollection = new Aspose.Cells.DigitalSignatures.DigitalSignatureCollection();
//Create new certificate
System.Security.Cryptography.X509Certificates.X509Certificate2 certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certFileName, password);
//Create new digital signature and add it in digital signature collection
Aspose.Cells.DigitalSignatures.DigitalSignature signature = new Aspose.Cells.DigitalSignatures.DigitalSignature(certificate, "Aspose.Cells added new digital signature in existing digitally signed workbook.", DateTime.Now);
dsCollection.Add(signature);
//Add digital signature collection inside the workbook
workbook.AddDigitalSignature(dsCollection);
//Save the workbook and dispose it.
workbook.Save(outputDir + "outputDigitallySignedByCells.xlsx");
workbook.Dispose();