用Node.js通过C++检测工作表是否密码保护

Contents
[ ]

Aspose.Cells for Node.js via C++已暴露Protection.isProtectedWithPassword()属性,用于检测工作表是否受到密码保护。布尔类型的Protection.isProtectedWithPassword()属性,如果Worksheet被密码保护,则返回true,否则返回false

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, "sample.xlsx");
// Create an instance of Workbook and load a spreadsheet
const book = new AsposeCells.Workbook(filePath);

// Access the protected Worksheet
const sheet = book.getWorksheets().get(0);

// Check if Worksheet is password protected
if (sheet.getProtection().isProtectedWithPassword()) {
console.log("Worksheet is password protected");
} else {
console.log("Worksheet is not password protected");
}