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