使用证书为VBA代码项目进行数字签名
Contents
[
Hide
]
您可以使用Aspose.Cells的Workbook.VbaProject.Sign()方法为VBA代码项目进行数字签名。请按照以下步骤检查您的Excel文件是否使用证书进行了数字签名。
- 从“开发人员”选项卡中单击“Visual Basic”以打开“Visual Basic for Applications IDE”
- 在“Visual Basic for Applications IDE”中单击“工具” > “数字签名…”
将显示“数字签名表单”,显示文档是否已使用证书进行数字签名。
使用C#为VBA代码项目使用证书进行数字签名
以下示例代码说明了如何使用Workbook.VbaProject.Sign()方法。这是示例代码的输入和输出文件。您可以使用任何Excel文件和任何证书来测试此代码。
- 用于示例代码的源Excel文件
- 示例pfx文件用于创建数字签名。请在计算机上安装它以运行此代码。其密码为1234。
- 示例代码生成的输出Excel文件
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
string password = "1234"; | |
string pfxPath = sourceDir + "sampleDigitallySignVbaProjectWithCertificate.pfx"; | |
string comment = "Signing Digital Signature using Aspose.Cells"; | |
// Set Digital Signature | |
DigitalSignature digitalSignature = new DigitalSignature(File.ReadAllBytes(pfxPath), password, comment, DateTime.Now); | |
// Create workbook object from excel file | |
Workbook workbook = new Workbook(sourceDir + "sampleDigitallySignVbaProjectWithCertificate.xlsm"); | |
// Sign VBA Code Project with Digital Signature | |
workbook.VbaProject.Sign(digitalSignature); | |
// Save the workbook | |
workbook.Save(outputDir + "outputDigitallySignVbaProjectWithCertificate.xlsm"); |