ワークシートがパスワード保護されているかどうかをNode.jsをC++経由で検出
Contents
[
Hide
]
ワークブックとワークシートは別々に保護可能です。例えば、スプレッドシートには1つ以上のパスワード保護されたワークシートが含まれる場合がありますが、スプレッドシート自体は保護されている場合とそうでない場合があります。Aspose.Cells APIは、指定されたワークシートがパスワード保護されているかどうかを検出する手段を提供します。この記事は、そのためにAspose.Cells for Node.js via C++ APIの使用例を示しています。
Aspose.Cells for Node.js via C++は、ワークシートがパスワード保護されているかどうかを検出するためのProtection.isProtectedWithPassword()プロパティを公開しています。Boolean型の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");
}