حماية كلمة السر لمشروع VBA لسجل العمل الخاص بـ Excel

سيناريوهات الاستخدام المحتملة

يمكنك حماية كلمة المرور لمشروع VBA (البرنامج النصي الأساسي للتطبيقات) لمصنف باستخدام Aspose.Cells باستخدام طريقة VbaProject.protect()

الكود المثالي

الكود النموذجي التالي يحمل ملف Excel عيني، يصل إلى مشروع VBA الخاص به، ويحميه بكلمة مرور. في النهاية، يحفظه كملف Excel الناتج.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(PasswordProtecttheVBAProjectofExcelWorkbook.class) + "WorkbookVBAProject/";
// Load your source Excel file.
Workbook wb = new Workbook(dataDir + "samplePasswordProtectVBAProject.xlsm");
// Access the VBA project of the workbook.
VbaProject vbaProject = wb.getVbaProject();
// Lock the VBA project for viewing with password.
vbaProject.protect(true, "11");
// Save the output Excel file
wb.save(dataDir + "outputPasswordProtectVBAProject.xlsm");