使用证书为VBA代码项目进行数字签名
Contents
[
Hide
]
您可以使用Aspose.Cells for Python via .NET的Workbook.vba_project.sign()方法对您的VBA代码项目进行数字签名。请按照以下步骤检查您的Excel文件是否已用证书数字签名。
- 从“开发人员”选项卡中单击“Visual Basic”以打开“Visual Basic for Applications IDE”
- 在“Visual Basic for Applications IDE”中单击“工具” > “数字签名…”
将显示“数字签名表单”,显示文档是否已使用证书进行数字签名。
在Python中用证书对VBA代码项目进行数字签名
以下示例代码说明了如何使用Workbook.vba_project.sign()方法。这是示例代码的输入和输出文件。您可以使用任何Excel文件和任何证书来测试此代码。
- 用于示例代码的源Excel文件
- 示例pfx文件用于创建数字签名。请在计算机上安装它以运行此代码。其密码为1234。
- 示例代码生成的输出Excel文件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
from aspose.cells.digitalsignatures import DigitalSignature | |
from datetime import datetime | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
password = "1234" | |
pfxPath = sourceDir + "sampleDigitallySignVbaProjectWithCertificate.pfx" | |
comment = "Signing Digital Signature using Aspose.Cells" | |
# Set Digital Signature | |
digitalSignature = DigitalSignature(open(pfxPath, "rb").read(), password, comment, datetime.now()) | |
# Create workbook object from excel file | |
workbook = Workbook(sourceDir + "sampleDigitallySignVbaProjectWithCertificate.xlsm") | |
# Sign VBA Code Project with Digital Signature | |
workbook.vba_project.sign(digitalSignature) | |
# Save the workbook | |
workbook.save(outputDir + "outputDigitallySignVbaProjectWithCertificate.xlsm") |