添加 Cell 数据验证
Contents
[
Hide
]
Aspose.Cells.GridWeb 允许您添加数据验证使用 GridWorksheet.Validations.Add() 方法。使用此方法,您必须指定Cell 范围.但是如果你想在单个 GridCell 中创建数据验证,那么你可以直接使用 GridCell.CreateValidation() 方法来完成。同样,您可以删除数据验证从 GridCell 使用 GridCell.RemoveValidation() 方法。
在 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; |