Table of Contents

XlsFile.CheckDataValidationsInWorkbook Method

Checks if all the cells in the file inside data validations have values that are valid according to the data validation specifications.

Syntax

Namespace: FlexCel.XlsAdapter

public override TCellAddress[] CheckDataValidationsInWorkbook(Int32 maxErrors)

Parameters

<-> Parameter Type Description
maxErrors Int32 The maximum number of errors reported by this method. To avoid getting a too big list, set it to a number like 100. If set to 0 or a negative number, the full list of errors will be returned, which can be very big.

Returns

An array with the first maxErrors cells that do not conform to the data validation. And empty array if all the cells conform.

Examples

The following code will mark in red all the cells in a file which don't comply with the data validations and save the file with a different name:

    static void CheckDataValidationsInWorkbook(string sourceFileName, string targetFileName)
    {
        var xls = new XlsFile(sourceFileName, true);
        var cellsWithErrors = xls.CheckDataValidationsInWorkbook(0);

        var fmt = xls.GetStyle(xls.GetBuiltInStyleName(TBuiltInStyle.Bad, 0), true);
        int xf = xls.AddFormat(fmt);

        for (int i = 0; i < cellsWithErrors.Length; i++)
        {
            xls.ActiveSheetByName = cellsWithErrors[i].Sheet;
            xls.SetCellFormat(cellsWithErrors[i].Row, cellsWithErrors[i].Col, xf);
        }
        xls.Save(targetFileName);

    }

See also