Cripta e Decripta file Excel con Node.js tramite C++

Utilizzando Microsoft Excel

Per impostare le impostazioni di crittografia del file in Microsoft Excel (qui Microsoft Excel 2003):

  1. Dal menu Strumenti, seleziona Opzioni. Verrà visualizzata una finestra di dialogo.
  2. Seleziona la scheda Sicurezza.
  3. Inserisci una password e fai clic su Avanzate
  4. Scegli il tipo di crittografia e conferma la password.

Criptare il file Excel con Aspose.Cells for Node.js via C++

Il seguente esempio mostra come criptare e proteggere con password un file Excel usando l’API Aspose.Cells.

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Book1.xls");

// Instantiate a Workbook object.
// Open an excel file.
const workbook = new AsposeCells.Workbook(filePath);

// Specify XOR encryption type.
workbook.setEncryptionOptions(AsposeCells.EncryptionType.XOR, 40);

// Specify Strong Encryption type (RC4, Microsoft Strong Cryptographic Provider).
workbook.setEncryptionOptions(AsposeCells.EncryptionType.StrongCryptographicProvider, 128);

// Password protect the file.
workbook.getSettings().setPassword("1234");

// Save the excel file.
workbook.save(path.join(dataDir, "encryptedBook1.out.xls"));

Specificare l’opzione Password per modificare

L’esempio seguente mostra come impostare l’opzione Password per modificare per un file esistente utilizzando l’API Aspose.Cells di Microsoft Excel.

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// Instantiate a Workbook object.
// Open an excel file.
const workbook = new AsposeCells.Workbook(path.join(dataDir, "Book1.xls"));

// Set the password for modification.
workbook.getSettings().getWriteProtection().setPassword("1234");

// Save the excel file.
workbook.save(path.join(dataDir, "SpecifyPasswordToModifyOption.out.xls"));

Decriptare file Excel con Aspose.Cells for Node.js via C++

È molto facile aprire un file Excel protetto da password e decriptarlo usando l’API Aspose.Cells come mostrato nel codice seguente:

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Book1.xlsx");

// Open encrypted file with password.
const loadOptions = new AsposeCells.LoadOptions();
loadOptions.setPassword("password");
const workbook = new AsposeCells.Workbook(filePath, loadOptions);

// Remove password.
workbook.getSettings().setPassword(null);

// Save the file.
workbook.save(filePath);

Argomenti avanzati