Format liczby EPPlus

Mam arkusz Excela wygenerowany za pomocą Epplus, doświadczam pewnych problemów i chciałbym być kierowany przez kogoś, kto rozwiązał podobne wyzwanie. Muszę zastosować formatowanie liczb do podwójnej wartości i chcę przedstawić ją w Excelu w ten sposób.

  • 8 -> 8.0
  • 12 -> 12.0
  • 14.54 -> 14.5
  • 0 -> 0.0

Oto Mój kod

ws.Cells[row, col].Style.Numberformat.Format = "##0.0";

Ostateczny plik Excela zawsze dołącza E+0 do końca tego formatu i dlatego prezentuje ostateczny zamiast tego takie wartości.

  • 8 - > 8.0 E + 0
  • 12 - > 12.0 E + 0
  • 14,54 - > 14,5 E + 0
  • 0 - > 000.0 E + 0

Kiedy sprawdzam komórki formatu wygenerowanego arkusza excel, widzę, że mój format wygląda jak # # 0.0 E + 2 zamiast # # 0.0, który zastosowałem. Co może być nie tak?

Author: VDWWD, 2016-10-24

2 answers

Oto kilka opcji formatu liczb dla EPPlus:

//integer (not really needed unless you need to round numbers, Excel with use default cell properties)
ws.Cells["A1:A25"].Style.Numberformat.Format = "0";

//integer without displaying the number 0 in the cell
ws.Cells["A1:A25"].Style.Numberformat.Format = "#";

//number with 1 decimal place
ws.Cells["A1:A25"].Style.Numberformat.Format = "0.0";

//number with 2 decimal places
ws.Cells["A1:A25"].Style.Numberformat.Format = "0.00";

//number with 2 decimal places and thousand separator
ws.Cells["A1:A25"].Style.Numberformat.Format = "#,##0.00";

//number with 2 decimal places and thousand separator and money symbol
ws.Cells["A1:A25"].Style.Numberformat.Format = "€#,##0.00";

//percentage (1 = 100%, 0.01 = 1%)
ws.Cells["A1:A25"].Style.Numberformat.Format = "0%";

//accounting number format
ws.Cells["A1:A25"].Style.Numberformat.Format = "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-";

Nie zmieniaj separatorów dziesiętnych i tysięcy na własne lokalizacja. Excel zrobi to za Ciebie.

Poprzez żądanie niektórych opcji formatowania DateTime.

//default DateTime pattern
worksheet.Cells["A1:A25"].Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern;

//custom DateTime pattern
worksheet.Cells["A1:A25"].Style.Numberformat.Format = "dd-MM-yyyy HH:mm";
 61
Author: VDWWD,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-16 14:48:58

Dla listy standardowych / przykładowych formatów można:

  1. w programie Excel kliknij prawym przyciskiem myszy dowolną komórkę, wybierz "Formatuj komórki"
  2. w kategorii: lista wybierz żądany format
  3. Następnie wybierz "Custom" i w polu tekstowym "Type"wyświetli żądany / wybrany format.

To działa dla każdego typu danych w XL.

 -1
Author: Zar Shardan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-27 10:23:43