Ryan Chong
Ryan Chong

Reputation: 180

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.

Upvotes: 3

Views: 3550

Answers (3)

Mathieu
Mathieu

Reputation: 39

I'm using this code:

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

Upvotes: 1

ChuongHo
ChuongHo

Reputation: 87

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

app.ErrorCheckingOptions.BackgroundChecking = false;

Upvotes: 0

Byron Wall
Byron Wall

Reputation: 4010

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).

Upvotes: 1

Related Questions