Check Password to modify using Aspose.Cells

Java code to check Password to modify using Aspose.Cells

The following sample codes load the source Excel file. It has a password to open as 1234 and password to modify as 5678. The code first checks if 567 is correct password to modify and it returns false and then it checks if 5678 is password to modify and it returns 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);

Console Output generated by the Java code

Here is the Console Output of the above sample code after loading the source Excel file.

Is 567 correct Password to modify: false

Is 5678 correct Password to modify: true