检查VBA项目是否受保护并已锁定以供查看

使用C#检查VBA项目是否受保护并已锁定以供查看

Aspose.Cells允许您检查Excel文件的VBA(Visual Basic for Applications)项目是否受保护并已锁定以供查看。为此,该API提供了VbaProject.IslockedForViewing属性。如果已锁定以供查看,则VbaProject.IslockedForViewing属性将返回true

示例代码

以下示例代码加载了示例Excel文件,并检查Excel文件的VBA(Visual Basic for Applications)项目是否受到保护并锁定以供查看。还请参见其控制台输出以供参考。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//Load your source Excel file.
Workbook wb = new Workbook(dataDir + "sampleCheckifVBAProjectisProtected.xlsm");
//Access the VBA project of the workbook.
Aspose.Cells.Vba.VbaProject vbaProject = wb.VbaProject;
//Whether "Lock project for viewing" is true or not.
Console.WriteLine("Is VBA Project Locked for Viewing: " + vbaProject.IslockedForViewing);

控制台输出

这是上述示例代码在使用提供的示例Excel文件时执行时的控制台输出。

Is VBA Project Locked for Viewing: True