Skip to main content
Row

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DataValidationCollection.GetInvalidCells() Method

Returns cells that do not meet the data validation criteria.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

IEnumerable<Cell> GetInvalidCells()

#Returns

Type Description
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:

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();
        }
    }
}
See Also