使用Aspose.Cells检查修改密码

使用 Aspose.Cells 检查修改密码的 Java 代码

以下示例代码加载了 source Excel 文件。它具有打开密码 1234 和修改密码 5678。代码首先检查 567 是否是正确的修改密码,如果返回 false,然后检查 5678 是否为修改密码,如果返回 true

// 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(CheckPassword.class) + "articles/";
// Specify password to open inside the load options
LoadOptions opts = new LoadOptions();
opts.setPassword("1234");
// Open the source Excel file with load options
Workbook workbook = new Workbook(dataDir + "Book1.xlsx", opts);
// Check if 567 is Password to modify
boolean ret = workbook.getSettings().getWriteProtection().validatePassword("567");
System.out.println("Is 567 correct Password to modify: " + ret);
// Check if 5678 is Password to modify
ret = workbook.getSettings().getWriteProtection().validatePassword("5678");
System.out.println("Is 5678 correct Password to modify: " + ret);

Java代码生成的控制台输出

这是以上示例代码加载 源Excel 文件后的控制台输出。

Is 567 correct Password to modify: false

Is 5678 correct Password to modify: true