使用 Aspose.Cells 检查修改密码
Contents
[
Hide
]
你可以分配一个打开密码和一个修改密码在 Microsoft Excel 中创建工作簿时。请查看此屏幕截图,其中显示了 Microsoft Excel 提供的用于指定这些密码的界面。
有时,您需要检查给定的密码是否与修改密码以编程方式。 Aspose.Cells提供workbook.getSettings().getWriteProtection().validatePassword() 方法,您可以使用该方法检查给定的要修改的密码是否正确。
Java 检查密码使用 Aspose.Cells 修改密码
以下示例代码加载源Excel文件。它有一个密码可以打开1234和密码修改为5678.代码首先检查是否567是要修改的正确密码并返回错误的然后它检查是否5678是要修改的密码,它返回真的.
This file contains hidden or 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(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