Insert formatted values as currency type while using EPPlus

此生再无相见时 提交于 2019-12-08 13:18:41

Your formatting is correct. You needs to covert values to its native types

Use this code, it should work:

using (var package = new ExcelPackage())
{
    var worksheet = package.Workbook.Worksheets.Add("Sales list - ");
    worksheet.Cells[1, 1].Style.Numberformat.Format = "$###,###,##0.00";
    worksheet.Cells[1, 1].Value =Convert.ToDecimal(24558.4780);

    package.SaveAs(new FileInfo(path));
}

Indices start from 1 in Excel.

This code

using (var package = new ExcelPackage())
{
    var worksheet = package.Workbook.Worksheets.Add("Sales list - ");
    worksheet.Cells[1, 1].Style.Numberformat.Format = "$###,###,##0.00";
    worksheet.Cells[1, 1].Value = 24558.4780;

    package.SaveAs(new FileInfo(path));
}

produces $24 558,48 for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!