Verificare la password utilizzata per proteggere il foglio di lavoro
Contents
[
Hide
]
Aspose.Cells Le API hanno migliorato il fileProtezione class introducendo alcune utili proprietà e metodi. Uno di questi metodi è il[verifica la password](https://reference.aspose.com/cells/java/com.aspose.cells/protection#verifyPassword(java.lang.String)che consente di specificare una password come istanza di String e verifica se la stessa password è stata utilizzata per proteggere il foglio di lavoro.
Verificare la password utilizzata per proteggere il foglio di lavoro
IlProtezione.verificaPassword restituisce il metodoVERO se la password specificata corrisponde alla password utilizzata per proteggere il foglio di lavoro specificato,falso se la password specificata non corrisponde. La parte di codice seguente utilizza ilProtezione.verificaPassword metodo in combinazione conProtection.isProtectedWithPasswordproperty per rilevare la protezione tramite password e verifica la password.
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.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"); | |
} | |
} |