Crittografa e decifra file ODS con C++

Crittografa con OpenOffice Calc

  1. Seleziona Salva come e clicca sulla casella Salva con password.
  2. Fai clic sul pulsante Salva.
  3. Digita la password desiderata nei campi Inserisci password per aprire e Conferma password nella finestra Imposta password che si apre.
  4. Fare clic sul pulsante OK per salvare il file.

Cripta file ODS con Aspose.Cells for C++

Per cifrare un file ODS, caricare il file e impostare il valore WorkbookSettings.GetPassword() alla password effettiva prima di salvarlo. Il file ODS cifrato risultante può essere aperto solo con OpenOffice.

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

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

    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C++

    // Source directory path
    U16String sourceDir = u"..\\Data\\01_SourceDirectory\\";

    // Output directory path
    U16String outputDir = u"..\\Data\\02_OutputDirectory\\";

    // Open an ODS file
    Workbook workbook(sourceDir + u"sampleODSFile.ods");

    // Password protect the file
    workbook.GetSettings().SetPassword(u"1234");

    // Save the ODS file
    workbook.Save(outputDir + u"outputEncryptedODSFile.ods");

    std::cout << "ODS file password protected and saved successfully!" << std::endl;

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

Decripta file ODS con Aspose.Cells for C++

Per decriptare un file ODS, caricare il file fornendo una password nella proprietà LoadOptions.GetPassword(). Una volta caricato il file, impostare la stringa WorkbookSettings.GetPassword() su null.

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

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

    // Path to the source directory
    U16String sourceDir = u"..\\Data\\01_SourceDirectory\\";

    // Output directory
    U16String outputDir = u"..\\Data\\02_OutputDirectory\\";

    // Open an encrypted ODS file
    LoadOptions loadOptions(LoadFormat::Ods);

    // Set original password
    loadOptions.SetPassword(u"1234");

    // Load the encrypted ODS file with the appropriate load options
    Workbook workbook(sourceDir + u"sampleEncryptedODSFile.ods", loadOptions);

    // Set the password to null
    workbook.GetSettings().SetPassword(nullptr);

    // Save the decrypted ODS file
    workbook.Save(outputDir + u"outputDecryptedODSFile.ods");

    std::cout << "Decrypted ODS file saved successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}