Bug when converting a sheet to CSV #2959

Open
opened 2023-06-05 09:20:31 +00:00 by lako12 · 1 comment

Hi,

I'm trying to convert the sheet of an excel file to csv by calling this method
XLSX.writeFile(workBookFinal, "./temp/tempCsv.csv", {bookType: "csv"});
everything works fine. However, I noticed that if a cell contains the string ID as text, quotes are inserted inside the csv.
For example if I have a row with 3 cells valued like this
image
i will get:
A,B,"ID"
I expect:
A, B,ID

Thanks

Hi, I'm trying to convert the sheet of an excel file to csv by calling this method `XLSX.writeFile(workBookFinal, "./temp/tempCsv.csv", {bookType: "csv"});` everything works fine. However, I noticed that if a cell contains the string `ID` as text, quotes are inserted inside the csv. For example if I have a row with 3 cells valued like this ![image](/attachments/c5791352-4dbb-4a17-ad11-99aea1255bd2) i will get: A,B,"ID" I expect: A, B,ID Thanks
lako12 changed title from Bug durante la conversione di un fogli in csv to Bug when converting a sheet to CSV 2023-06-05 09:36:47 +00:00
Owner

Excel treats files that start with ID as "Symbolic Link": https://web.archive.org/web/20140929030911/http://support2.microsoft.com/kb/323626

The parser enforces the same logic.

To ensure that there is no confusion, the writer always wraps every ID in double quotes. The quotes are not needed in any other place.

To immediately fix this issue (only quote the first column), https://git.sheetjs.com/sheetjs/sheetjs/src/branch/master/bits/90_utils.js#L115 should be changed to

if(txt == "ID" && row.length == 0) txt = '"ID"';
Excel treats files that start with ID as "Symbolic Link": https://web.archive.org/web/20140929030911/http://support2.microsoft.com/kb/323626 The parser enforces the same logic. To ensure that there is no confusion, the writer always wraps every ID in double quotes. The quotes are not needed in any other place. To immediately fix this issue (only quote the first column), https://git.sheetjs.com/sheetjs/sheetjs/src/branch/master/bits/90_utils.js#L115 should be changed to ```js if(txt == "ID" && row.length == 0) txt = '"ID"'; ```
Sign in to join this conversation.
No Milestone
No Assignees
2 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#2959
No description provided.