clarketm / TableExport

The simple, easy-to-implement library to export HTML tables to xlsx, xls, csv, and txt files.
https://tableexport.travismclarke.com/
Apache License 2.0
888 stars 289 forks source link

Escape cell if there's a comma #158

Open harryadel opened 6 years ago

harryadel commented 6 years ago

Table cells that contains commas are usually ignored if not causing misalignment, so we check if the text string contains a comma to escape it.

((val.textContent.indexOf(',') > -1) ? '"\'' : '"') + settings.formatValue(val.textContent.replace(/"/g, '""')) + '"';

The ES6 version of this solution is

`"'${settings.formatValue(val.textContent.replace(/"/g, '""'))}"`;

But we opted for the ES5 one for backwards compatibility, thanks!