支持对Excel XP以来的高级保护设置

介绍

Aspose.Cells for Python via .NET 支持使用XAdES签名对工作簿进行签名。为此,API 提供了 DigitalSignature 类和 XAdESType 枚举。

如何为Excel添加XAdES签名

以下代码片段演示了如何使用 DigitalSignature 类 对 源文件 的工作簿进行签名。

from aspose.cells import Workbook
from aspose.cells.digitalsignatures import DigitalSignature, DigitalSignatureCollection, XAdESType
from datetime import datetime
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Source directory
sourceDir = RunExamples.Get_SourceDirectory()
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
workbook = Workbook(sourceDir + "sourceFile.xlsx")
password = "pfxPassword"
pfx = "pfxFile"
signature = DigitalSignature(open(pfx, "rb").read(), password, "testXAdES", datetime.now())
signature.x_ad_es_type = XAdESType.X_AD_ES
dsCollection = DigitalSignatureCollection()
dsCollection.add(signature)
workbook.set_digital_signature(dsCollection)
workbook.save(outputDir + "XAdESSignatureSupport_out.xlsx")