Back to Devexpress

DataValidationCollection.GetInvalidCells() Method

officefileapi-devexpress-dot-spreadsheet-dot-datavalidationcollection.md

latest3.3 KB
Original Source

DataValidationCollection.GetInvalidCells() Method

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

Declaration

csharp
IEnumerable<Cell> GetInvalidCells()
vb
Function GetInvalidCells As IEnumerable(Of Cell)

Returns

TypeDescription
IEnumerable<Cell>

A IEnumerable<T><Cell,> collection of cells containing invalid data.

|

Remarks

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:

csharp
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();
        }
    }
}
vb
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

DataValidationCollection Members

DevExpress.Spreadsheet Namespace