EPPlus number format EPPlus number format asp.net asp.net

EPPlus number format


Here are some number format options for EPPlus:

//integer (not really needed unless you need to round numbers, Excel will use default cell properties)ws.Cells["A1:A25"].Style.Numberformat.Format = "0";//integer without displaying the number 0 in the cellws.Cells["A1:A25"].Style.Numberformat.Format = "#";//number with 1 decimal placews.Cells["A1:A25"].Style.Numberformat.Format = "0.0";//number with 2 decimal placesws.Cells["A1:A25"].Style.Numberformat.Format = "0.00";//number with 2 decimal places and thousand separatorws.Cells["A1:A25"].Style.Numberformat.Format = "#,##0.00";//number with 2 decimal places and thousand separator and money symbolws.Cells["A1:A25"].Style.Numberformat.Format = "€#,##0.00";//percentage (1 = 100%, 0.01 = 1%)ws.Cells["A1:A25"].Style.Numberformat.Format = "0%";//accounting number formatws.Cells["A1:A25"].Style.Numberformat.Format = "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-";

Don't change the decimal and thousand separators to your own localization. Excel will do that for you.

By request some DateTime formatting options.

//default DateTime patternworksheet.Cells["A1:A25"].Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern;//custom DateTime patternworksheet.Cells["A1:A25"].Style.Numberformat.Format = "dd-MM-yyyy HH:mm";


Addition to Accepted Answer, because value Accept Object you must pass Number to Value For Example if your input is in string :

var input = "5";    ws.Cells["A1:A25"].Value = double.Parse(input);


Another addition to the accepted answer: you can use nullable values and the formatting all looks good BUT it ends up being a string in Excel and you can't SUM, AVG etc.

So make sure you use the actual Value of the nullable.