Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EPPlus Format Cell as "Accounting" Number

Tags:

c#

excel

epplus

In Excel you can format numbers in the following format:

enter image description here enter image description here

I'd like to format a cell with this format in EPPlus, but I don't see that property available:

enter image description here

I've looked a number of other formats, , but none of them are the same. I also tried to set the "BuildIn" number(it has no setter, this didn't work). I'm trying to use the system format, vs roll my own custom format. Is it possible to use the "Accounting" format with EPPlus?

like image 696
David Rogers Avatar asked May 11 '18 21:05

David Rogers


2 Answers

EPPlus does not include the number formats built into Excel so you must set it manually.

All the built-in formats in Excel have an actual number format. For accounting, the format is:

-$* #,##0.00-;-$* #,##0.00_-;-$* "-"??-;-@-

The format above may differ depending on your region/settings. To see what the format is for any built-in formats:

  1. Right-click a cell and select Format Cells

  2. Click on your built-in format, in this case Accounting Image of the Accounting format

  3. Click on Custom to see the format of the previously selected format Image of the Accounting format in the Custom category to show actual format

Apply the format to your cells:

ws.Cells["A1:A5"].Style.Numberformat.Format = "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-";
like image 185
singularhum Avatar answered Oct 03 '22 02:10

singularhum


I used this format is simulating same as "Accounting Number" in the Excel.

ws.Cells["A1:A5"].Style.Numberformat.Format = "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"
like image 24
Kiah Han Avatar answered Oct 03 '22 01:10

Kiah Han