Protect and Unprotect Workbook Structure with Node.js via C++

Protect and unprotect Workbook Structure in MS Excel

protect and unprotect workbook structure

  1. Click Review > Protect Workbook.
  2. Enter a password in the Password box.
  3. Select OK, re-enter the password to confirm it, and then select OK again.

Protect Workbook Structure Using Aspose.Cells for Node.js via C++

Only need the following simple lines of code to implement protecting workbook structure of Excel files.

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();
// Protect workbook structure.
workbook.protect(AsposeCells.ProtectionType.Structure, "password");
// Save Excel file.
workbook.save(filePath);

Unprotect Workbook Structure Using Aspose.Cells for Node.js via C++

Unprotecting workbook structure is easy with Aspose.Cells API.

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 an Excel file which workbook structure is protected.
const workbook = new AsposeCells.Workbook(filePath);
// Unprotect workbook structure.
workbook.unprotect("password");
// Save Excel file.
workbook.save(filePath);