Proteger y desbloquear la hoja de cálculo con C++

Proteger y desbloquear la hoja en MS Excel

proteger y desproteger Hoja de Cálculo

  1. Haga clic en Revisar > Proteger Hoja.
  2. Ingrese una contraseña en el cuadro de Contraseña.
  3. Seleccione las opciones de permitir.
  4. Seleccione Aceptar, vuelva a ingresar la contraseña para confirmarla y luego seleccione Aceptar nuevamente.

Proteger hoja usando Aspose.Cells for C++

Solo necesitas las siguientes líneas de código simples para implementar la protección de la estructura del libro de trabajo de archivos de Excel.

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

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

    // Create a new workbook
    Workbook workbook;

    // Get the first worksheet
    Worksheet sheet = workbook.GetWorksheets().Get(0);

    // Protect contents of the worksheet
    sheet.Protect(ProtectionType::Contents);

    // Protect worksheet with password
    sheet.GetProtection().SetPassword(u"test");

    // Save as Excel file
    workbook.Save(u"Book1.xlsx");

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

    Aspose::Cells::Cleanup();
}

Desproteger hoja usando Aspose.Cells for C++

Desproteger la hoja de cálculo es fácil con la API de Aspose.Cells. Si la hoja de cálculo está protegida con contraseña, se requiere una contraseña correcta.

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

using namespace Aspose::Cells;

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

    // Create a new workbook
    Workbook workbook(u"Book1.xlsx");

    // Get the first worksheet
    Worksheet sheet = workbook.GetWorksheets().Get(0);

    // Unprotect the worksheet with password
    sheet.Unprotect(u"password");

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

    std::cout << "Worksheet unprotected successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}

Temas avanzados