D.R.
D.R.

Reputation: 21224

Excel Interop adds slashes to NumberFormat

I wanted to set the NumberFormat of a whole column via Excel Interop:

column.NumberFormat = "# ##0";

However, Excel adds an additional slash (opening the document shows #\ ##0).

I've found the following related question: Excel interop adding slashes in my number formatting string

However, using column.NumberFormatLocal, I've run into an exception:

Unhandled Exception: System.Runtime.InteropServices.COMException: Unable to set the NumberFormatLocal property of the Range class

Any ideas?

Upvotes: 2

Views: 1073

Answers (1)

D.R.
D.R.

Reputation: 21224

I could solve the problem by using the en-US separator instead:

column.NumberFormat = "#,##0"; // Note the comma

I'm not sure why. My system locale and my application's CultureInfo are both de-AT. Also my system thousands separator is de-AT (i.e., a space).

For some reason Excel Interop is nevertheless requiring the en-US separator.

Upvotes: 1

Related Questions