Exporting currency formatting with Excelbuilderjs

Asked

Viewed 55 times

2

I’m using the Excelbuilderjs to produce an Excel spreadsheet on demand and offer as a download to the customer. Ideally, this needs to be done on the client, not on the server, and the library works very well in this respect.

However I encountered a problem when creating formatted cells as 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 a fiddle who demonstrates it working:

http://jsfiddle.net/6ndTq/

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

1234567,89000

Opening the cell formatting, there is the following:

#,##000

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

#.##0,00

I tried some variations of this formatting unsuccessfully. What can I do?

1 answer

1

Turn left to reach right.

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

http://jsfiddle.net/6ndTq/1/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.