密码保护Excel工作簿的VBA项目
Contents
[
Hide
]
可能的使用场景
您可以使用 Aspose.Cells 使用密码保护工作簿的 VBA(Visual Basic for Applications)项目[VbaProject.保护()](https://reference.aspose.com/cells/java/com.aspose.cells/vbaproject#protect(boolean,%20java.lang.String)) 方法。
示例代码
下面的示例代码加载示例 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"); |