Découvrez 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 utilisantVbaProject.isProtected()méthode

Exemple de code

L’exemple de code 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 si son projet VBA est protégé ou non. Veuillez consulter sa sortie console pour une référence. Avant protection,VbaProject.isProtected() Retourfaux mais après protection, il revientvrai.

// 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 de l’exemple de code ci-dessus pour référence.

 IsProtected - Before Protecting VBA Project: false

IsProtected - After Protecting VBA Project: true