使用Node.js通过C++验证用来保护工作表的密码
Contents
[
Hide
]
Aspose.Cells API增强了Protection类,新增了一些有用的属性和方法。其中一个方法是Protection.verifyPassword(string),它允许指定密码(字符串实例)并验证是否用该密码保护了Worksheet。
如果指定的密码与用于保护工作表的密码匹配,则Protection.verifyPassword(string)方法返回true,否则返回false。以下代码结合使用Protection.verifyPassword(string)方法和Protection.isProtectedWithPassword()属性来检测密码保护状态并验证密码。
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// 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 workbook = new AsposeCells.Workbook(filePath);
// Access the protected Worksheet
const sheet = workbook.getWorksheets().get(0);
// Check if Worksheet is password protected
if (sheet.getProtection().isProtectedWithPassword()) {
// Verify the password used to protect the Worksheet
if (sheet.getProtection().verifyPassword("1234")) {
console.log("Specified password has matched");
} else {
console.log("Specified password has not matched");
}
}