Vérifier si le projet VBA est protégé
Découvrir si le projet VBA est protégé en Python
Vous pouvez vérifier si le projet VBA (Visual Basic Applications) de votre fichier Excel est protégé ou non avec Aspose.Cells pour Python via .NET en utilisant la propriété VbaProject.is_protected.
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.is_protected retourne false mais après la protection, il retourne true.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create a workbook. | |
wb = Workbook() | |
# Access the VBA project of the workbook. | |
vbaProj = wb.vba_project | |
# Find out if VBA Project is Protected using IsProtected property. | |
print("IsProtected - Before Protecting VBA Project: " + str(vbaProj.is_protected)) | |
# Protect the VBA project. | |
vbaProj.protect(True, "11") | |
# Find out if VBA Project is Protected using IsProtected property. | |
print("IsProtected - After Protecting VBA Project: " + str(vbaProj.is_protected)) |
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