Search code examples
c#excelexport-to-excel

How to validate Excel range that it has error/warning using .NET?


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.


Solution

  • 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#.