إضافة تحقق من صحة البيانات للخلية
Contents
[
Hide
]
يتيح لك Aspose.Cells.GridWeb إضافة التحقق من البيانات باستخدام طريقة GridWorksheet.Validations.Add(). باستخدام هذه الطريقة، يجب عليك تحديد نطاق الخلية. ولكن إذا كنت ترغب في إنشاء التحقق من البيانات في خلية واحدة في الشبكة المربعية يمكنك فعل ذلك مباشرة باستخدام طريقة GridCell.CreateValidation(). بالمثل، يمكنك إزالة التحقق من البيانات من خلية الشبكة باستخدام طريقة GridCell.RemoveValidation().
إنشاء التحقق من البيانات في خلية من GridWeb
الكود النموذجي التالي ينشئ التحقق من البيانات في خلية 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; |