officefileapi-devexpress-dot-spreadsheet-dot-datavalidationcollection.md
Returns cells that do not meet the data validation criteria.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
IEnumerable<Cell> GetInvalidCells()
Function GetInvalidCells As IEnumerable(Of Cell)
| Type | Description |
|---|---|
| IEnumerable<Cell> |
A IEnumerable<T><Cell,> collection of cells containing invalid data.
|
Note that the GetInvalidCells property returns only first 255 invalid cells, other invalid entries are ignored. If there are no data validation errors in a worksheet, the GetInvalidCells property returns an empty collection.
The code sample below shows how to use the GetInvalidCells method to check whether loaded document contains invalid cells:
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadDocument("DataValidation_template.xlsx");
IsDocumentValid(workbook);
}
private static void IsDocumentValid(Workbook workbook)
{
foreach (Worksheet workSheet in workbook.Worksheets)
{
var invalidCells = workSheet.DataValidations.GetInvalidCells().Count();
if (invalidCells == 0)
{
Console.WriteLine(string.Format("The {0} worksheet does not contain invalid cells", workSheet.Name));
Console.ReadLine();
}
else
{
Console.WriteLine(string.Format("The {0} worksheet contains {1} invalid cells",workSheet.Name, invalidCells));
Console.ReadLine();
}
}
}
Private Shared Sub Main(ByVal args As String())
Dim workbook As Workbook = New Workbook()
workbook.LoadDocument("DataValidation_template.xlsx")
IsDocumentValid(workbook)
End Sub
Private Shared Sub IsDocumentValid(ByVal workBook As Workbook)
For Each workSheet As Worksheet In workBook.Worksheets
Dim invalidCells = workSheet.DataValidations.GetInvalidCells().Count()
If invalidCells = 0 Then
Console.WriteLine(String.Format("The {0} worksheet does not contain invalid cells", workSheet.Name))
Console.ReadLine()
Else
Console.WriteLine(String.Format("The {0} worksheet contains {1} invalid cells", workSheet.Name, invalidCells))
End If
Console.ReadLine()
Next
End Sub
See Also
DataValidationCollection Interface