Bestätigen Sie das Kennwort, das zum Schutz des Arbeitsblatts verwendet wird
Contents
[
Hide
]
Aspose.Cells APIs haben die verbessertSchutz Klasse durch die Einführung einiger nützlicher Eigenschaften und Methoden. Eine solche Methode ist diePasswort bestätigen, die die Angabe eines Kennworts als Instanz von String ermöglicht und überprüft, ob dasselbe Kennwort zum Schutz des Arbeitsblatts verwendet wurde.
Bestätigen Sie das Kennwort, das zum Schutz des Arbeitsblatts verwendet wird
DasProtection.verifyPassword Methode gibt zurückwahr wenn das angegebene Passwort mit dem Passwort übereinstimmt, das zum Schutz des angegebenen Arbeitsblatts verwendet wird,FALSCH wenn das angegebene Passwort nicht übereinstimmt. Der folgende Codeabschnitt verwendet dieProtection.verifyPassword Methode in Verbindung mitProtection.isProtectedWithPassword-Eigenschaft, um den Kennwortschutz zu erkennen, und überprüft das Kennwort.
This file contains 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.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"); | |
} | |
} |