ノード.jsとC++を使用したシートのパスワード保護の検証
Contents
[
Hide
]
Aspose.Cells APIは、便利なプロパティとメソッドを導入してProtectionクラスを強化しました。その一つがProtection.verifyPassword(string)であり、パスワードをstringとして指定し、同じパスワードがシートの保護に使用されたかどうかを検証します。
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");
}
}