查看 VBA 项目是否已受保护
Contents
[
Hide
]
在Python中检查VBA项目是否已被保护
您可以使用Aspose.Cells for Python via .NET的VbaProject.is_protected属性来判断Excel文件的VBA(Visual Basic Applications)项目是否受到保护。
示例代码
以下示例代码创建一个工作簿,然后检查其 VBA 项目是否受保护。然后保护 VBA 项目并再次检查其是否受保护。请参考控制台输出。在保护之前,VbaProject.is_protected 返回 false,但在保护后,它返回 true。
This file contains hidden or 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
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)) |
控制台输出
这是上述示例代码的控制台输出供参考。
IsProtected - Before Protecting VBA Project: False
IsProtected - After Protecting VBA Project: True