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 è ilVerifica la password che consente di specificare una password come istanza dicorda e verifica se la stessa password è stata utilizzata per proteggere ilFoglio di lavoro.
IlProtezione.VerificaPassword metodo restituisceVEROse la password specificata corrisponde alla password utilizzata per proteggere il foglio di lavoro specificato efalso se la password specificata non corrisponde. La parte di codice seguente utilizza ilProtezione.VerificaPassword metodo in combinazione conProtezione.IsProtectedWithPasswordproperty per rilevare la protezione tramite password e verifica la password.
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook and load a spreadsheet | |
var book = new Workbook(dataDir + "Sample.xlsx"); | |
// Access the protected Worksheet | |
var sheet = book.Worksheets[0]; | |
// Check if Worksheet is password protected | |
if (sheet.Protection.IsProtectedWithPassword) | |
{ | |
// Verify the password used to protect the Worksheet | |
if (sheet.Protection.VerifyPassword("1234")) | |
{ | |
Console.WriteLine("Specified password has matched"); | |
} | |
else | |
{ | |
Console.WriteLine("Specified password has not matched"); | |
} | |
} |