查看 VBA 项目是否受保护
Contents
[
Hide
]
在 C# 中查看 VBA 项目是否受保护
您可以使用 Aspose.Cells 查看 Excel 文件的 VBA(Visual Basic 应用程序)项目是否受保护VbaProject.IsProtected财产。
示例代码
以下示例代码创建一个工作簿,然后检查其 VBA 项目是否受保护。然后它保护 VBA 项目并再次检查其 VBA 项目是否受到保护。请查看其控制台输出以供参考。保护前,VbaProject.IsProtected回报错误的但在保护之后,它返回真的.
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
// 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