Vérifier si le projet VBA est protégé

Scénarios d’utilisation possibles

Vous pouvez savoir si le projet VBA (Visual Basic Applications) de votre fichier Excel est protégé ou non avec Aspose.Cells en utilisant la méthode VbaProject.isProtected()

Code d’exemple

Le code d’exemple suivant crée un classeur, puis vérifie si son projet VBA est protégé ou non. Ensuite, il protège le projet VBA et vérifie à nouveau s’il est protégé ou non. Veuillez consulter sa sortie console pour référence. Avant la protection, VbaProject.isProtected() renvoie false mais après la protection, il renvoie true.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create a workbook.
Workbook wb = new Workbook();
// Access the VBA project of the workbook.
VbaProject vbaProj = wb.getVbaProject();
// Find out if VBA Project is Protected using IsProtected property.
System.out.println("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.
System.out.println("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