通过Node.js和C++保护和取消保护工作表

在 MS Excel 中保护和取消保护工作表

保护和取消保护工作表

  1. 点击 审阅 > 保护工作表
  2. 密码框 中输入密码。
  3. 选择 允许 选项。
  4. 选择 确定,重新输入密码以确认,然后再次选择 确定

使用Aspose.Cells for Node.js via C++保护工作表

只需要以下简单代码行来实现保护 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");

使用Aspose.Cells for Node.js via C++取消保护工作表

使用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");
// 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");

高级主题