amcharts / export

Apache License 2.0
56 stars 33 forks source link

Exporting floats in XLSX as comma-separated #31

Closed Cyb0org closed 8 years ago

Cyb0org commented 8 years ago

I'm trying to get floats i18n

                "export": {
                    "enabled": true,
                    "menuReviver": function(cfg,li) {
                        if ( cfg.format == "CSV" ) {
                            cfg.delimiter = "\t";
                            cfg.quotes = false;
                        }
                        if ( cfg.format == "XSLX" ) {
                            cfg.stringify = false; // false by default
                        }
                        return li;
                    },
                    "processData": function (data) {
                        for(i = 0, j = data.length; i < j; i++)
                        {
                            data[i]['time'] = parseFloat(data[i]['time']).toLocaleString();
                        }
                        return data;
                    }
                },

I've managed to use CSV as a data exporter witch commas as decimal separator, but for XLSX those values are exported as string values (with apostrophe).

maertz commented 8 years ago

The "XLSX" export (you misspelled it on the menuReviver) obtains the type of the value and according to that it defines the cell type. In your case "time" is a "string"-type because you convert your float to "toLocalString()". The decimal separator depends on the local settings within your XLSX-Viewer, mine for instance uses "comma" because it's the default of Germany.

Cyb0org commented 8 years ago

And now it's working - problem was "toLocalString()" which was added after trying to get it to work. Dunno why I've left that in a code. :)

Thanks!