Vérifier le mot de passe utilisé pour protéger la feuille de calcul avec Node.js via C++
La méthode Protection.verifyPassword(string) retourne true si le mot de passe spécifié correspond au mot de passe utilisé pour protéger la feuille de calcul donnée et false dans le cas contraire. Le code suivant utilise la méthode Protection.verifyPassword(string) en conjonction avec la propriété Protection.isProtectedWithPassword() pour détecter la protection par mot de passe et vérifier ce dernier.
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");
}
}