Hi ,
In our application I am using Infragistics.Excel to export the file. But I am not able to apply the Currency format for numeic values. Please how can i specify the currency format.
Ex:- 10,235.00 Ex: 0
Could you please respond soon will be appreciable because this is our immediate requirement and going to production today EOD.
Code snippet:-
Right now I am converting the value to string and applying the format. This cause the different problems. so please let me know the proper solution. If provide the sample application to me will be great helpful to me...
if (value != null && value.ToString() == "0") cell.Value = value.ToString(); else cell.Value = string.Format("{0:0,0}", value); cell.CellFormat.VerticalAlignment = VerticalCellAlignment.Center; cell.CellFormat.Alignment = HorizontalCellAlignment.Right;
The default currency format in Excel is this: $#,##0.00
Set this on the cell.CellFormat.FormatString property.
Mike,
Thanks for your Quick response.I have applied the following format.
cell.Value = value; cell.CellFormat.FormatString = "#,##0;(#,##0);0";
It is working fine. But now its not working for %. Could you please paste me the format string for Percentage.
Thanks
Anil Kumar
The format for percentage (with 2 decimal places) is 0.00%
By the way, you can find these strings by right-clicking on a cell a choosing "Format Cells...", going to the "Number" tab, selecting the format you need, and then going to the "Custom" category at the bottom. In the "Type" text box on the right, you will see the format string.
Hi Mike,
Thanks for your Quick reply and informing me about finding the Format. It worked.
But One doubt when I apply the Percentage. value is being multiplied by 100.
For ex:- value is 2 But In excel shows 200%.
Please let me know the solution...
That is how percentage formatting works. If you want to show 2%, the actual value of the cell needs to be 0.02.
Thank You for quickly responding for the queries.
Just so you know, storing the values as doubles instead of decimals will result is much better performance and memory usage in the Excel library. And since values are stored in the Excel files as doubles anyway, you won't lose any more precision during a save operation than you would have lost anyway.
Nevermind Its Friday :) was sending variables as a string instead of a decimal DOH !
Team,
I am using the currency format as well it works fine however when the spreadsheet is opened it is being loaded as a text field. I have been searching for a way to actually set the column to be of a decimal value for the entire column but I am not able to see how to set this excel column during code to be a decimal type column for vb.net any help is greatly appreciated.