Vérifier le mot de passe utilisé pour protéger la feuille avec C++

Contents
[ ]

La méthode Protection.VerifyPassword retourne true si le mot de passe spécifié correspond au mot de passe utilisé pour protéger la feuille donnée, et false s’il ne correspond pas. Le code suivant utilise la méthode Protection.VerifyPassword en conjonction avec la propriété Protection.IsProtectedWithPassword pour détecter la protection par mot de passe et vérifier le mot de passe.

#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;
}