Converting Excel cell to percentage using epplus

Deadly 提交于 2019-12-10 12:38:38

问题


I would like to convert the value in to 2 decimal places. I am using EPPlus if the value is 66.6666667 and I would like to show it as 66.66% I tried the following code but its not working.

   foreach (var dc in dateColumns)
   {
       sheet.Cells[2, dc, rowCount + 1, dc].Style.Numberformat.Format = "###,##%";
   }

Please help.


回答1:


I found it!

I tried

 foreach (var dc in dateColumns)
  {
    sheet.Cells[2, dc, rowCount + 1, dc].Style.Numberformat.Format ="#0\\.00%";
   }



回答2:


The correct formula is as follows:

 foreach (var dc in dateColumns)
  {
    sheet.Cells[2, dc, rowCount + 1, dc].Style.Numberformat.Format ="#0.00%";
  }

The Double slash in "#0\\.00%" leads to very unusual numbers when you try to expand the decimal places later




回答3:


As far as I checked format you set via epp is just a common Excel cell format.

In my case this was really helpful



来源:https://stackoverflow.com/questions/17281809/converting-excel-cell-to-percentage-using-epplus

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