Passwort zum Ändern mit Aspose.Cells überprüfen

Java-Code zum Überprüfen des Änderungspassworts mit Aspose.Cells

Die folgenden Beispielscodes laden die Quell-Excel-Datei. Sie hat ein Öffnungspasswort 1234 und ein Änderungspasswort 5678. Der Code überprüft zunächst, ob 567 das korrekte Änderungspasswort ist, und gibt false zurück. Dann wird überprüft, ob 5678 das Änderungspasswort ist, und es wird true zurückgegeben.

// 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);

Konsolenausgabe generiert durch den Java-Code

Hier ist die Konsolenausgabe des obigen Beispielcodes nach dem Laden der Quell-Excel-Datei.

Is 567 correct Password to modify: false

Is 5678 correct Password to modify: true