'How to ignore the format error flag in the cell number format

My code:

columns = ws.get_Range("A:F", System.Type.Missing);
columns.NumberFormat = "@";

After I debug the program, there is green color flag beside my number cells.

Expectation:

Remove the green color flag after debugging.

What I investigated:

https://msdn.microsoft.com/en-us/library/office/ff195953.aspx

From the MSDN itself, it only showed VBA can ignore the error in the cells. But i not really believe that c# is unable to do it.



Solution 1:[1]

There is an object on the Application called ErrorCheckingOptions. You can change the NumberAsText property from true to false.

Application.ErrorCheckingOptions.NumberAsText = false;

See: https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.errorcheckingoptions.numberastext(v=office.11).aspx

Note that this is a global (Application-level) option. I haven't tested, but it is likely that this option will persist across Excel instances (that is, once you close and reopen Excel).

Solution 2:[2]

Im using this, it will ignore and not show in Excel.

app.ErrorCheckingOptions.BackgroundChecking = false;

Solution 3:[3]

I'm using this code:

excelRange.Cells.Value = yourValue; // Must be set before the Ignore setting
excelRange.Cells.Errors[Excel.XlErrorChecks.xlNumberAsText].Ignore = true;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Byron Wall
Solution 2 Uwe Keim
Solution 3