2

I want to validate range of excel worksheet (e.g. "A10:B20") to check that is it has error or NA value or not? How to do that in C#?

P.S. I find similar topic (Excel range usage question (cell error checking)) but that topic is not thing I need.

2 Answers 2

1

The key is to check for the data type of the value held in the cell. If the data type is an Integer (Int32), then the value held is a CVErr value. To check for #N/A, the cell would be an Integer data type (not a Double!) holding the value -2146826246.

For more details, see the stack overflow question How to know if a cell has an error in the formula in C#.

Sign up to request clarification or add additional context in comments.

Comments

0

This might help you.First read the data from the excel.Please see this stack over flow question. Convert Excel Range to ADO.NET DataSet or DataTable, etc. Then iterate each row from the data table like

    foreach (DataRow row in sheetTable.Rows)
    {
        foreach (DataColumn column in sheetTable.Columns)
        {
            // Check what ever you want to check
            if (row[column].ToString().Equals("Error") || row[column] ==null)
            {
                // do something
            }
        }
    }

1 Comment

I need to validate data without import it to DataTable, did you have any other idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.