tags:

views:

33

answers:

1

Hey everyone,

I'm attempting to format a cell in excel to the currency format. So I go into excel, record a macro of me converting an ordinary cell to a currency format, take a look at the vb script and see that it outputs the following:

NumberFormat = "$ #,##0.00"

So i take that format and paste it into my code, it works to the extent that im getting the currency character before the values in my excel sheet. However, the format of the cell is still a number and excel places a little green triangle at the bottom left of the cell informing me that the format is incorrect (which it is, cos its supposed to be currency, but its set to number) is there any way in c# to actually set the cell to a "Currency" format?

thanks

A: 

Not sure I understand your question:
In Excel all numeric values including currency, integers and date/time are held as floating-point doubles. The Format of a value only controls how it is presented in the rendering (visible) layer.
The green triangle tests do not include tests for formatting.
Is the problem that you are creating a text value rather than a numeric value?

Charles Williams
No the values im setting the cells to are numeric. To better understand my question, if you right click on a cell in excel, and click format cell, there is a list of different formats that include "Number" and "Currency" and other types, is there a way for me to set a cells formatting to "Currency" using the excel interop, I tried to do that using NumberFormat but it didnt seem to work
Walter Sharp
You could try setting the style to Currency.<br/> But I don't think its the numeric formatting that is the problem since there are no green triangle checks for formatting, apart from the one checking for numbers stored as text.<br/> Maybe you should post your code.
Charles Williams
BTW, If a number is entered as string/text or formatted as Text then subsequently formatting it as currency does not convert it back to a number.
Charles Williams