Prüfen, ob die digitale Signatur des VBA Codes gültig ist
Contents
[
Hide
]
Aspose.Cells ermöglicht es Ihnen, mithilfe der Workbook.VbaProject.IsValidSigned-Eigenschaft zu überprüfen, ob die digitale Signatur des VBA-Codes gültig ist. Es gibt true zurück, wenn die Signatur gültig ist, andernfalls false. Die digitale Signatur des VBA-Codes wird ungültig, wenn Sie den VBA-Code ändern.
Überprüfen Sie, ob die digitale Signatur des VBA-Codes in C# 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.
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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(dataDir + "sampleVBAProjectSigned.xlsm"); | |
// Signature is valid | |
Console.WriteLine("Is VBA Code Project Valid Signed: " + workbook.VbaProject.IsValidSigned); | |
// Modify the VBA Code, save the workbook then reload | |
// VBA Code Signature will now be invalid | |
string code = workbook.VbaProject.Modules[1].Codes; | |
code = code.Replace("Welcome to Aspose", "Welcome to Aspose.Cells"); | |
workbook.VbaProject.Modules[1].Codes = code; | |
// Save | |
workbook.Save(dataDir + "output_out.xlsm"); | |
// Reload | |
workbook = new Workbook(dataDir + "output_out.xlsm"); | |
// Now the signature is invalid | |
Console.WriteLine("Is VBA Code Project Valid Signed: " + workbook.VbaProject.IsValidSigned); |