Exporting currency formatting with ExcelBuilderJS

2

I am using ExcelBuilderJS to produce an Excel spreadsheet on demand and download it to the customer. Ideally, this needs to be done on the client, not the server, and the library works very well in that respect.

However, I encountered a problem when creating cells formatted as an accounting. My code can be summarized in the following:

var workbook = Excel.createWorkbook();
var sheet = workbook.createWorksheet({name: "Teste de Moeda"});
workbook.addWorksheet(sheet);

var currency = workbook.getStyleSheet().createFormat({
    format: "#.##0,00"
});

var data = [[ // Essa é a célula A1
    {value: 1234567.89, // Deve exibir como "1.234.567,89" no excel
     metadata: {style: currency.id}}
]];

sheet.setData(data);
sheet.setColumns([{width: 15}]);
saveAs(Excel.createFile(workbook, {type: "blob"}), "moeda.xlsx");

Here's a fiddle that shows it working:

link

The problem is that when I open the result, I see the following:

Openingtheformattingofthecell,therearethefollowing:

Clearly it was not #,##000 what I typed in the code. If you manually change to #.##0,00 which is what is in the code, the format appears as it should:

I tried some variations of this format without being successful. What can I do?

    
asked by anonymous 25.07.2014 / 16:57

1 answer

1

Turn left to get to the right.

To get the format #.##0,00 you must use the format #,##0.00 in the code. The reason? Hard to say. Maybe it is that the whole file must be saved with American locale and excel does the translation at the moment of reading the file.

link

    
25.07.2014 / 18:21