Protéger et déprotéger la structure du classeur avec C++

Protéger et déprotéger la structure du classeur dans MS Excel

Protéger et déprotéger la structure du classeur

  1. Cliquez sur Relecture > Protéger le classeur.
  2. Entrez un mot de passe dans la boîte de mot de passe.
  3. Sélectionnez OK, saisissez à nouveau le mot de passe pour le confirmer, puis sélectionnez à nouveau OK.

Protéger la structure du classeur en utilisant Aspose.Cells for C++

Il suffit d’utiliser les lignes de code suivantes pour implémenter la protection de la structure du classeur Excel.

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

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

    // Create a new workbook
    Workbook workbook;

    // Protect workbook structure with a password
    workbook.Protect(ProtectionType::Structure, u"password");

    // Save the workbook to a file
    workbook.Save(u"Book1.xlsx");

    std::cout << "Workbook created and protected successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}

Déprotéger la structure du classeur en utilisant Aspose.Cells for C++

La déprotection de la structure du classeur est facile avec l’API Aspose.Cells.

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

using namespace Aspose::Cells;

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

    // Open an Excel file which workbook structure is protected.
    U16String inputFilePath = u"Book1.xlsx";
    Workbook workbook(inputFilePath);

    // Unprotect workbook structure.
    workbook.Unprotect(u"password");

    // Save Excel file.
    workbook.Save(inputFilePath);

    std::cout << "Workbook structure unprotected and saved successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}