Protéger et Déprotéger la feuille de calcul avec Node.js via C++

Protéger et déprotéger une feuille de calcul dans MS Excel

Protéger et déprotéger la feuille de calcul

  1. Cliquez sur Révision > Protéger la feuille.
  2. Entrez un mot de passe dans la boîte de mot de passe.
  3. Sélectionnez les options autoriser.
  4. Sélectionnez OK, saisissez à nouveau le mot de passe pour le confirmer, puis sélectionnez à nouveau OK.

Protéger la feuille de calcul en utilisant Aspose.Cells for Node.js via C++

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

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

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create a new file.
const workbook = new AsposeCells.Workbook();
// Gets the first worksheet.
const sheet = workbook.getWorksheets().get(0);
// Protect contents of the worksheet.
sheet.protect(AsposeCells.ProtectionType.Contents);
// Protect worksheet with password.
sheet.getProtection().setPassword("test");
// Save as Excel file.
workbook.save("Book1.xlsx");

Déprotéger la feuille de calcul en utilisant Aspose.Cells for Node.js via C++

La déprotection de la feuille de calcul est facile avec l’API Aspose.Cells. Si la feuille est protégée par mot de passe, un mot de passe correct est requis.

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");
// Create a new file.
const workbook = new AsposeCells.Workbook(filePath);
// Gets the first worksheet.
const sheet = workbook.getWorksheets().get(0);
// Protect contents of the worksheet.
sheet.unprotect("password");
// Save Excel file.
workbook.save("Book1.xlsx");

Sujets avancés