Verificar la contraseña utilizada para proteger la hoja de cálculo

Contents
[ ]

El método Protection.VerifyPassword devuelve true si la contraseña especificada coincide con la contraseña utilizada para proteger la hoja de cálculo dada y false si la contraseña especificada no coincide. El siguiente fragmento de código utiliza el método Protection.VerifyPassword en conjunto con la propiedad Protection.IsProtectedWithPassword para detectar la protección con contraseña y verificar la contraseña.

// 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");
}
}