Hücre Değerinin Veri Doğrulama Kurallarına Uygun Olup Olmadığını Doğrulayın

Hücre Değerinin Veri Doğrulama Kurallarına Uygun Olup Olmadığını Doğrulayın

Bazen, bir verilen değerin, hücreye uygulanan veri doğrulama kurallarına uyup uymadığını dinamik olarak doğrulamak gereklidir. Bu amaçla, Aspose.Cells API’leri cell.getValidationValue() yöntemini sağlar. Bir hücredeki değer, o hücreye uygulanan veri doğrulama kuralını karşılamıyorsa False döndürür, aksi takdirde True döndürür.

Aşağıdaki örnek Microsoft Excel dosyası, aşağıdaki örnek kodla test etmek için kullanılır: C1 hücresinin ondalık veri doğrulama uygulandığını ve yalnızca 10 ile 20 arasındaki değerleri kabul edeceğini görebilirsiniz. Hücre değeri 10 ile 20 arasında olduğunda, cell.getValidationValue() yöntemi True döndürecektir, aksi halde False döndürecektir.

todo:image_alt_text

Aşağıdaki örnek kod, cell.getValidationValue() yönteminin nasıl çalıştığını gösterir. İlk olarak, C1’e değer 3 girer. Bu, veri doğrulama kuralını karşılamadığı için, cell.getValidationValue() yöntemi False döndürür. Sonra, C1’e değer 15 girer. Bu değer, veri doğrulama kuralını karşıladığı için, cell.getValidationValue() yöntemi True döndürür. Benzer şekilde, 30 değeri için False döndürür.

Bir Hücre Değerinin Veri Doğrulama Kurallarına Uygun Olup Olmadığını Doğrulamak için Java Kodu

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(VerifyCellValueSatisfiesDataValidationRules.class);
// Instantiate the workbook from sample Excel file
Workbook workbook = new Workbook(dataDir + "Sample1.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
/*
* Access Cell C1. Cell C1 has the Decimal Validation applied on it.It can take only the values Between 10 and 20
*/
Cell cell = worksheet.getCells().get("C1");
// Enter 3 inside this cell. Since it is not between 10 and 20, it should fail the validation
cell.putValue(3);
// Check if number 3 satisfies the Data Validation rule applied on this cell
System.out.println("Is 3 a Valid Value for this Cell: " + cell.getValidationValue());
// Enter 15 inside this cell. Since it is between 10 and 20, it should succeed the validation
cell.putValue(15);
// Check if number 15 satisfies the Data Validation rule applied on this cell
System.out.println("Is 15 a Valid Value for this Cell: " + cell.getValidationValue());
// Enter 30 inside this cell. Since it is not between 10 and 20, it should fail the validation again
cell.putValue(30);
// Check if number 30 satisfies the Data Validation rule applied on this cell
System.out.println("Is 30 a Valid Value for this Cell: " + cell.getValidationValue());

Örnek Kod Tarafından Oluşturulan Konsol Çıktısı

Aşağıdaki örnek Excel dosyasıyla çalıştırıldığında oluşturulan konsol çıktısı burada gösterilmektedir.

Is 3 a Valid Value for this Cell: False

Is 15 a Valid Value for this Cell: True

Is 30 a Valid Value for this Cell: False