获取应用于单元格的验证
Contents
[
Hide
]
您可以使用 Aspose.Cells for Node.js 获取应用于单元格的验证。Aspose.Cells 提供了 Cell.getValidation() 方法来实现此功能。如果单元格没有应用验证,则返回 null。
同样,您可以使用 Worksheet.validations.getValidationInCell(number, number) 方法通过提供它的行和列索引来获取应用于单元格的验证。
使用 Node.js 获取应用于单元格验证的代码示例
下面的代码示例演示了如何获取应用到单元格的验证。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiate the workbook from sample Excel file | |
const workbook = new AsposeCells.Workbook(dataDir + "sample.xlsx"); | |
// Access its first worksheet | |
const worksheet = workbook.getWorksheets().get(0); | |
// Cell C1 has the Decimal Validation applied on it. It can take only the values Between 10 and 20 | |
const cell = worksheet.getCells().get("C1"); | |
// Access the validation applied on this cell | |
const validation = cell.getValidation(); | |
// Read various properties of the validation | |
console.log("Reading Properties of Validation"); | |
console.log("--------------------------------"); | |
console.log("Type: " + validation.getType()); | |
console.log("Operator: " + validation.getOperator()); | |
console.log("Formula1: " + validation.getFormula1()); | |
console.log("Formula2: " + validation.getFormula2()); | |
console.log("Ignore blank: " + validation.getIgnoreBlank()); |