Currency format is excelJS

21.1k views Asked by At

How do you format currency in exceljs?

All I've found is this from their docs...which I have no clue how to type so I pasted it, but it doesn't seem to work

// Set Column 3 to Currency Format 
ws.getColumn(3).numFmt = '�#,##0;[Red]-�#,##0';
3

There are 3 answers

2
tumelo On BEST ANSWER

Just took a little bit of tinkering with.

ws.getColumn(3).numFmt = '$#,##0.00;[Red]-$#,##0.00';

The #'s are optional digits. If you don't care about negative numbers being red you can leave it as $#,##0.00

0
Yacc On

An alternate to 343_Guilty_Spark's answer which is shorter and will be red for negative values:

const numFmtStr = '$#,##0.00_);[Red]($#,##0.00)'
cell.numFmt = numFmtStr

This will keep all the qualities of it, but be less complicated for Excel.

0
343_Guilty_Spark On

For the full Accounting format, eg left-justified '$', $- for $0.00, etc, you can use:

const numFmtStr = '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)';
cell.numFmt = numFmtStr;

see: What are .NumberFormat Options In Excel VBA?