Excel Dateien mit Node.js via C++ verschlüsseln und entschlüsseln

Verwendung von Microsoft Excel

Um die Dateiverschlüsselungseinstellungen in Microsoft Excel festzulegen (hier Microsoft Excel 2003):

  1. Wählen Sie im Menü Extras die Option Optionen aus. Es wird ein Dialogfeld angezeigt.
  2. Klicken Sie auf die Registerkarte Sicherheit.
  3. Geben Sie ein Passwort ein und klicken Sie auf Erweitert
  4. Wählen Sie den Verschlüsselungstyp aus und bestätigen Sie das Passwort.

Excel-Datei mit Aspose.Cells for Node.js via C++ verschlüsseln

Das folgende Beispiel zeigt, wie man eine Excel-Datei mit Aspose.Cells API verschlüsselt und passwortgeschützt macht.

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"));

Option zum Passwort zum Ändern angeben

Das folgende Beispiel zeigt, wie Sie die Passwort zum Ändern Microsoft Excel-Option für eine vorhandene Datei mithilfe der Aspose.Cells-API festlegen.

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"));

Entschlüsseln der Excel-Datei mit Aspose.Cells for Node.js via C++

Es ist sehr einfach, eine passwortgeschützte Excel-Datei mit Aspose.Cells API zu öffnen und zu entschlüsseln, wie im folgenden Code gezeigt:

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);

Erweiterte Themen