Herausfinden, ob das VBA Projekt geschützt ist

Ermitteln Sie, ob das VBA-Projekt in C# geschützt ist

Sie können mit Aspose.Cells über die VbaProject.IsProtected-Eigenschaft feststellen, ob das VBA (Visual Basic Applications)-Projekt Ihrer Excel-Datei geschützt ist oder nicht.

Beispielcode

Der folgende Beispielscode erstellt eine Arbeitsmappe und überprüft dann, ob ihr VBA-Projekt geschützt ist oder nicht. Anschließend schützt es das VBA-Projekt und überprüft erneut, ob ihr VBA-Projekt geschützt ist oder nicht. Bitte sehen Sie sich die Konsolenausgabe zur Referenz an. Vor dem Schutz gibt VbaProject.IsProtected false zurück, aber nach dem Schutz gibt sie true zurück.

// 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);

Konsolenausgabe

Dies ist die Konsolenausgabe des obigen Beispielcodes als Referenz.

IsProtected - Before Protecting VBA Project: False

IsProtected - After Protecting VBA Project: True