This project has moved and is read-only. For the latest updates, please go here.

Format Cell as currency

Jul 22, 2010 at 7:35 AM

Hi All,

First of all I want to Say Thanks for your support.

I am creating a excel sheet from scratch, am writing values directly to the excel.
all are fine. but my values represents in dollars.
for example if i want to write 200 , before writing 200 i will append $ to the value and write it in excel.
and am changing the style into number first and than into currency By using Below Statements
worksheet.Cells[startRow, 2, row, 13].Style.Numberformat.Format = "#,##0.00";
worksheet.Cells[startRow, 2, row, 13].Style.Numberformat.Format = "\"$\"#,##0.00_);(\"$\"#,##0.00)";
but it is changing into currency but am facing a problem.
if we open an excel 2007  and write 100 value than it will automatically aligns to right side. and if we write negative value when it is in currency format it will display in red colour.
but here am facing a problem is values are not aliging right, so am aligning them to right by using 
worksheet.Cells[startRow, 2, row, 13].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
my problem is values should be formatted to currency and if any negative value is there it should display in redcolor to the user.
Any suggestions or Example will be useful for me.

Please do the needful.

Jul 22, 2010 at 11:35 AM
Edited Jul 22, 2010 at 11:36 AM

I think we dont have conditional color feature yet....but you can code by yourself, when you set your cell value, check if it is a negative number and do what you want.

Jul 22, 2010 at 2:56 PM

Thank u.

for color it is ok.

but is there any idea to convert it to currency.



Jul 25, 2010 at 1:58 PM


If you used Excelpackage you properbly convert your numbers to strings using the ToString metod?

If you do that it will be treated as a string instread of a number and will not be formatted.

Use numeric datatypes for numbers and the DateTime datattype for Date/Time instead of strings.