在列中使用验证
Contents
[
Hide
]
在我们之前的一个主题中,我们已经讨论过验证,但那是在工作表中的验证的上下文中(开发人员可以参考此主题以获取有关验证和验证模式的一般信息)。在本主题中,我们将解释有关列的验证。使用此功能,开发人员可以在工作表的任何列上应用验证规则。让我们详细讨论一下。
添加列验证
要向列添加任何类型的验证,请按照以下步骤操作:
- 向您的表单中添加Aspose.Cells.GridDesktop控件
- 访问任何所需的工作表
- 向任何列添加所需的验证
重要:有关验证类型(或验证模式,如必需验证、正则表达式验证和自定义验证)和实施自定义验证的更多信息,请参阅在工作表中使用验证。
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 | |
// Accessing first worksheet of the Grid | |
Worksheet sheet = gridDesktop1.Worksheets[0]; | |
// Adding Is Required Validation to a column | |
sheet.Columns[2].AddValidation(true, ""); | |
// Adding simple Regular Expression Validation to a column | |
sheet.Columns[4].AddValidation(true, @"\d+"); | |
// Adding complex Regular Expression Validation to a column | |
sheet.Columns[6].AddValidation(true, @"\d{4}-\d{2}-\d{2}"); | |
// Adding Custom Validation to a column | |
sheet.Columns[8].AddValidation(new CustomValidation()); |
访问列验证
要访问特定列验证,请按照以下步骤操作:
- 访问所需的工作表
- 在工作表中访问特定列验证
- 编辑验证属性(如果需要)
//Accessing first worksheet of the Grid
Worksheet sheet = gridDesktop1.Worksheets[0];
//Accessing the Validation object applied on a specific column
Validation validation = sheet.Columns[2].Validation;
//Editing the attributes of Validation
validation.IsRequired = true;
validation.RegEx = "";
validation.CustomValidation = null;
删除列验证
要从工作表中删除特定列验证,请按照以下步骤操作:
- 访问所需的工作表 从工作表中删除特定列Validation
//Accessing first worksheet of the Grid
Worksheet sheet = gridDesktop1.Worksheets[0];
//Removing the Validation applied on a specific column
sheet.Columns[2].RemoveValidation();