Vérifiez le mot de passe utilisé pour protéger la feuille de calcul
Vérifier le mot de passe utilisé pour protéger la feuille de calcul
La méthode Protection.verifyPassword renvoie vrai si le mot de passe spécifié correspond au mot de passe utilisé pour protéger la feuille de calcul donnée, faux si le mot de passe spécifié ne correspond pas. Le morceau de code suivant utilise la méthode Protection.verifyPassword en conjonction avec la propriété Protection.isProtectedWithPassword pour détecter la protection par mot de passe, et vérifie le mot de passe.
// 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.getDataDir(VerifyPasswordtoProtectWorksheet.class); | |
// Create an instance of Workbook and load a spreadsheet | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Access the protected Worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Check if Worksheet is password protected | |
if (sheet.getProtection().isProtectedWithPassword()) { | |
// Verify the password used to protect the Worksheet | |
if (sheet.getProtection().verifyPassword("password")) { | |
System.out.println("Specified password has matched"); | |
} else { | |
System.out.println("Specified password has not matched"); | |
} | |
} |