Verifica della password usata per proteggere il foglio di lavoro con C++

Contents
[ ]

Il metodo Protection.VerifyPassword restituisce true se la password specificata corrisponde alla password usata per proteggere il foglio di lavoro dato e false se la password specificata non corrisponde. Il seguente esempio di codice utilizza il metodo Protection.VerifyPassword in combinazione con la proprietà Protection.IsProtectedWithPassword per rilevare la protezione con password e verificare la password.

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Create an instance of Workbook and load a spreadsheet
    Workbook book(srcDir + u"Sample.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(u"1234"))
        {
            std::cout << "Specified password has matched" << std::endl;
        }
        else
        {
            std::cout << "Specified password has not matched" << std::endl;
        }
    }

    Aspose::Cells::Cleanup();
    return 0;
}