Vérifier si le projet VBA est protégé
Savoir si le projet VBA est protégé en C#
Vous pouvez voir si le projet VBA (Applications Visual Basic) de votre fichier Excel est protégé ou non avec Aspose.Cells en utilisant la propriété VbaProject.IsProtected.
Code d’exemple
Le code d’exemple suivant crée un classeur et vérifie ensuite si son projet VBA est protégé ou non. Ensuite, il protège le projet VBA et vérifie à nouveau si son projet VBA est protégé ou non. Veuillez consulter la sortie console pour référence. Avant la protection, VbaProject.IsProtected retourne false mais après la protection, il retourne true.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Create a workbook. | |
Workbook wb = new Workbook(); | |
//Access the VBA project of the workbook. | |
Aspose.Cells.Vba.VbaProject vbaProj = wb.VbaProject; | |
//Find out if VBA Project is Protected using IsProtected property. | |
Console.WriteLine("IsProtected - Before Protecting VBA Project: " + vbaProj.IsProtected); | |
//Protect the VBA project. | |
vbaProj.Protect(true, "11"); | |
//Find out if VBA Project is Protected using IsProtected property. | |
Console.WriteLine("IsProtected - After Protecting VBA Project: " + vbaProj.IsProtected); |
Sortie console
Il s’agit de la sortie console du code d’exemple ci-dessus pour référence.
IsProtected - Before Protecting VBA Project: False
IsProtected - After Protecting VBA Project: True