التحقق من كلمة المرور المستخدمة لحماية ورقة العمل مع Node.js عبر C++
Contents
[
Hide
]
قامت واجهات برمجة تطبيقات Aspose.Cells بتحسين فئة 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");
}
}