密码保护 Excel 工作簿的 VBA 项目
Contents
[
Hide
]
可能的使用场景
您可以使用Aspose.Cells的VbaProject.protect()方法来保护工作簿的VBA(Visual Basic for Applications)项目。
示例代码
下面的示例代码加载了示例Excel文件,访问其VBA项目,并用密码保护它。最后,将其另存为输出Excel文件。
This file contains 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-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"); |