添加单元格数据验证
Contents
[
Hide
]
Aspose.Cells.GridWeb允许您使用GridWorksheet.Validations.Add()方法添加数据验证。使用此方法,您必须指定单元格范围。但如果要在单个GridCell中创建数据验证,可以直接使用GridCell.CreateValidation()方法。同样,您可以使用GridCell.RemoveValidation()方法从GridCell中移除数据验证。
在 GridWeb 的 GridCell 中创建数据验证
下面的示例代码在 B3 单元格中创建了数据验证。如果输入任何不在 20 到 40 之间的值,B3 单元格将以红色 XXXX的形式显示验证错误,如屏幕截图所示。
This file contains 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 | |
// Access first worksheet | |
GridWorksheet sheet = GridWeb1.WorkSheets[0]; | |
// Access cell B3 | |
GridCell cell = sheet.Cells["B3"]; | |
// Add validation inside the gridcell | |
// Any value which is not between 20 and 40 will cause error in a gridcell | |
GridValidation val = cell.CreateValidation(GridValidationType.WholeNumber, true); | |
val.Formula1 = "=20"; | |
val.Formula2 = "=40"; | |
val.Operator = GridOperatorType.Between; | |
val.ShowError = true; | |
val.ShowInput = true; |