在 Cell 上应用验证
Contents
[
Hide
]
您可以使用 Aspose.Cells 将验证应用于单元格。 Aspose.Cells 提供了Cell.GetValidation()为此目的的方法。如果没有对单元格应用验证,则返回 null。
同样,您可以使用工作表.Validations.GetValidationInCell方法通过提供其行和列索引来获取应用于单元格的验证。
C# 用于获取应用于 Cell 的验证的代码
下面的代码示例向您展示了如何在单元格上应用验证。
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate the workbook from sample Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access its first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Cell C1 has the Decimal Validation applied on it. It can take only the values Between 10 and 20 | |
Cell cell = worksheet.Cells["C1"]; | |
// Access the valditation applied on this cell | |
Validation validation = cell.GetValidation(); | |
// Read various properties of the validation | |
Console.WriteLine("Reading Properties of Validation"); | |
Console.WriteLine("--------------------------------"); | |
Console.WriteLine("Type: " + validation.Type); | |
Console.WriteLine("Operator: " + validation.Operator); | |
Console.WriteLine("Formula1: " + validation.Formula1); | |
Console.WriteLine("Formula2: " + validation.Formula2); | |
Console.WriteLine("Ignore blank: " + validation.IgnoreBlank); |