Prüfen, ob die digitale Signatur des VBA Codes gültig ist

Überprüfen, ob die digitale Signatur von VBA-Code in Python gültig ist

Der folgende Code demonstriert die Verwendung dieser Eigenschaft anhand der Beispieldatei, die Sie über den bereitgestellten Link herunterladen können. Die gleiche Excel-Datei hat eine gültige Signatur, aber wenn wir ihren VBA-Code ändern und die Arbeitsmappe speichern, finden wir heraus, dass ihre Signatur ungültig geworden ist.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
workbook = Workbook(dataDir + "sampleVBAProjectSigned.xlsm")
# Signature is valid
print("Is VBA Code Project Valid Signed: " + str(workbook.vba_project.is_valid_signed))
# Modify the VBA Code, save the workbook then reload
# VBA Code Signature will now be invalid
code = workbook.vba_project.modules[1].codes
code = code.replace("Welcome to Aspose", "Welcome to Aspose.Cells")
workbook.vba_project.modules[1].codes = code
# Save
workbook.save(dataDir + "output_out.xlsm")
# Reload
workbook = Workbook(dataDir + "output_out.xlsm")
# Now the signature is invalid
print("Is VBA Code Project Valid Signed: " + str(workbook.vba_project.is_valid_signed))