Excel Çalışma Kitabının VBA Projesini Parola Koruması

C# kullanarak Excel çalışma kitabının VBA Projesini parola korumak

Aspose.Cells kullanarak, çalışma kitabının VBA (Görsel Temel Uygulamalar) Projesini VbaProject.Protect() yöntemi ile parola koruyabilirsiniz.

Örnek Kod

Aşağıdaki örnek kod, örnek Excel dosyasını yükler, VBA Projesine erişir ve onu bir parola ile korur. Son olarak, bunu çıktı Excel dosyası olarak kaydeder.

// 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 + "samplePasswordProtectVBAProject.xlsm");
//Access the VBA project of the workbook.
Aspose.Cells.Vba.VbaProject vbaProject = wb.VbaProject;
//Lock the VBA project for viewing with password.
vbaProject.Protect(true, "11");
//Save the output Excel file
wb.Save(dataDir + "outputPasswordProtectVBAProject.xlsm");