react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

Export CSV not working with a different encoding than UTF-8

Open luupqvinh opened this issue 6 years ago • 12 comments

Hello.

I want to export the content of the table in ANSI encoding. I must do that because Excel 2016 doesn't read utf-8 csv file correctly.

I pass the following options to ToolkitProvider exportOptions = { fileName: 'export.csv', noAutoBOM: false, // true or false, both won't work separator: ';', blobType: 'text/csv;charset=ansi' // also tried "application/octet-stream", etc. };

The file will always be exported in UTF-8.

I've seen this issue: https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/702 It doesn't work for me.

Maybe this is the solution ? https://github.com/eligrey/FileSaver.js/issues/28

Thanks for your reply.

luupqvinh avatar Dec 04 '19 16:12 luupqvinh

@luupqvinh we leverage fileSaver and in our source we did the same thing like eligrey/FileSaver.js#28. So I think so far I still also have no idea about this issue. maybe we can discover more detail from fileSaver, but need some time.

AllenFang avatar Dec 05 '19 12:12 AllenFang

@AllenFang could you upload an update for issue of the accents.? The problem is solved by adding "\uFEFF" before content. _fileSaver2.default.saveAs(new Blob(["\uFEFF"+content], { type: blobType }), fileName, noAutoBOM); In the file exporter.js

josemsp avatar Dec 11 '19 23:12 josemsp

Any updates on this issue?

g-akshay avatar Feb 10 '20 10:02 g-akshay

I am having the same problem... Cannot save file with ANSI encoding... Any solution?

gustavoergalves avatar Mar 04 '20 14:03 gustavoergalves

@AllenFang I add '\uFEFF' at transform func() for this code.

react-bootstrap-table2-toolkit/lib/src/csv/exporter.js
var transform = exports.transform = function transform(data, meta, columns, _, _ref) {
  var separator = _ref.separator,
      ignoreHeader = _ref.ignoreHeader,
      ignoreFooter = _ref.ignoreFooter;

  var visibleColumns = meta.filter(function (m) {
    return m.export;
  });
  var content = '\uFEFF';  **<================This**
  // extract csv header
  if (!ignoreHeader) {
    content += visibleColumns.map(function (m) {
      return '"' + m.header + '"';
    }).join(separator);
    content += '\n';
  }

the data is correct for excel. Please consider about this.

weezer924 avatar Mar 26 '20 04:03 weezer924

@AllenFang I would like to create a PR for this isuue.

weezer924 avatar Mar 26 '20 05:03 weezer924

@AllenFang I'm having the same issue when exporting to CSV with Chinese characters. And the solution above _fileSaver2.default.saveAs(new Blob(["\uFEFF"+content], { type: blobType }), fileName, noAutoBOM); works really well. Probably noAutoBOM option does not work with FileSaver.js any longer?

shp7724 avatar Mar 31 '20 10:03 shp7724

any fix?

luizhenriquerosa avatar Sep 23 '20 19:09 luizhenriquerosa

Any update ? Does PR #1128 can fix this annoying bug ?

Wait4Code avatar Nov 27 '20 16:11 Wait4Code

+1 the same issue.

illia-sh avatar May 20 '21 21:05 illia-sh

+1

damdka avatar Aug 19 '22 14:08 damdka

+1

goodloveone1 avatar Sep 01 '22 17:09 goodloveone1