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

可能的使用场景

Aspose.Cells for Python via .NET提供Workbook.add_digital_signature方法,用于给已签名的Excel文件添加数字签名。

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

以下示例代码演示了如何使用 Workbook.add_digital_signature 方法向已签名的Excel文件添加数字签名。请查看此代码中使用的 示例Excel文件。该文件已经数字签名。请查看代码生成的 输出Excel文件。这里我们使用了一个名为 AsposeDemo.pfx 的演示证书,密码为 aspose。屏幕截图展示了示例代码对示例Excel文件执行后的效果。

todo:image_alt_text

示例代码

from aspose.cells import Workbook
from aspose.cells.digitalsignatures import DigitalSignature, DigitalSignatureCollection
from datetime import datetime
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Load the workbook which is already digitally signed to add new digital signature
workbook = Workbook(sourceDir + "sampleDigitallySignedByCells.xlsx")
# Create the digital signature collection
dsCollection = DigitalSignatureCollection()
# Create new digital signature and add it in digital signature collection
# Cert must contain private key, it can be contructed from cert file or windows certificate collection. aa is password of cert
rawData = None
password = None
signature = DigitalSignature(rawData, password, "Aspose.Cells added new digital signature in existing digitally signed workbook.", datetime.now())
dsCollection.add(signature)
# Add digital signature collection inside the workbook
workbook.add_digital_signature(dsCollection)
# Save the workbook and dispose it.
workbook.save(outputDir + "outputDigitallySignedByCells.xlsx")