Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Excel cell to percentage using epplus

Tags:

c#

epplus

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.

like image 837
rach Avatar asked Jun 24 '13 17:06

rach


3 Answers

I found it!

I tried

 foreach (var dc in dateColumns)
  {
    sheet.Cells[2, dc, rowCount + 1, dc].Style.Numberformat.Format ="#0\\.00%";
   }
like image 109
rach Avatar answered Nov 08 '22 18:11

rach


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

like image 38
TsTeaTime Avatar answered Nov 08 '22 18:11

TsTeaTime


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

In my case this was really helpful

like image 3
Michael Brennt Avatar answered Nov 08 '22 18:11

Michael Brennt