Das Verifizieren des zum Schutz des Arbeitsblatts verwendeten Passworts
Die Methode Protection.VerifyPassword gibt true zurück, wenn das angegebene Passwort mit dem zum Schutz des entsprechenden Arbeitsblatts verwendeten Passwort übereinstimmt, und false, wenn das angegebene Passwort nicht übereinstimmt. Der folgende Code verwendet die Methode Protection.VerifyPassword in Verbindung mit der Eigenschaft Protection.IsProtectedWithPassword, um den Passwortschutz zu erkennen und das Passwort zu überprüfen.
// 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"); | |
} | |
} |