Signer numériquement un projet de code VBA avec un certificat

Signer numériquement un projet de code VBA avec un certificat en Python

Le code d’exemple suivant illustre comment utiliser la méthode Workbook.vba_project.sign(). Voici les fichiers d’entrée et de sortie du code d’exemple. Vous pouvez utiliser n’importe quel fichier Excel et n’importe quel certificat pour tester ce code.

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")