CSV file seems different depending on the program. #1024

Closed
opened 2018-03-07 01:55:23 +00:00 by hyeribo · 2 comments
hyeribo commented 2018-03-07 01:55:23 +00:00 (Migrated from github.com)

I made a csv file:
var stream = XLSX.stream.to_csv(ws);
stream.pipe(fs.createWriteStream(fileName));

then uploaded the file to S3 and returned url.

When I download the file and open it, it looks well on my pc. (open on OS X using Numbers.)
But when I trying to open the same file on window OS using ms office, characters are broken.
it's Korean characters. and I want to encode the file UTF-8.
How can I resolve this problem?

it's the file.
20180307105408.csv.zip

I made a csv file: var stream = XLSX.stream.to_csv(ws); stream.pipe(fs.createWriteStream(fileName)); then uploaded the file to S3 and returned url. When I download the file and open it, it looks well on my pc. (open on OS X using Numbers.) But when I trying to open the same file on window OS using ms office, characters are broken. it's Korean characters. and I want to encode the file UTF-8. How can I resolve this problem? it's the file. [20180307105408.csv.zip](https://github.com/SheetJS/js-xlsx/files/1787451/20180307105408.csv.zip)
SheetJSDev commented 2018-03-07 02:30:56 +00:00 (Migrated from github.com)

The utility currently doesn't (but should) write the UTF8 BOM. As a temporary workaround:

var stream = XLSX.stream.to_csv(ws);
var out = fs.createWriteStream(fileName);
out.on('open', function(fd) {
  out.write(new Buffer([0xEF,0xBB,0xBF]));
  stream.pipe(out);
});

If you would like to contribute a fix, in the write_csv_stream function add a line to push the BOM if it hasn't been written:

var BOM = false;
stream._read = function() {
	if(!BOM) { BOM = true; return stream.push("\uFEFF"); }
The utility currently doesn't (but should) write the UTF8 BOM. As a temporary workaround: ```js var stream = XLSX.stream.to_csv(ws); var out = fs.createWriteStream(fileName); out.on('open', function(fd) { out.write(new Buffer([0xEF,0xBB,0xBF])); stream.pipe(out); }); ``` If you would like to contribute a fix, in the [`write_csv_stream` function](https://github.com/SheetJS/js-xlsx/blob/master/bits/97_node.js#L18) add a line to push the BOM if it hasn't been written: ```js var BOM = false; stream._read = function() { if(!BOM) { BOM = true; return stream.push("\uFEFF"); } ```
hyeribo commented 2018-03-19 06:14:14 +00:00 (Migrated from github.com)

It works. Thanks!!

It works. Thanks!!
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#1024
No description provided.