SheetJS / sheetjs

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs
https://sheetjs.com/
Apache License 2.0
34.78k stars 7.99k forks source link

Unexpected behavior in the `sheet_to_csv` utility function #2785

Closed rmitra-chub closed 1 year ago

rmitra-chub commented 1 year ago

There's a possible bug in the utils.sheet_to_csv function (https://docs.sheetjs.com/docs/api/utilities#delimiter-separated-output) Function arguments:

Output: "sample header 1\tsample header 2\n\"\"\"sample text 1\"\tsample text 2\n" Expected Output: "sample header 1\tsample header 2\n\"sample text 1\tsample text 2\n"

The output is duplicating the double quote if there is one inside one of the values (in this example, A2).

SheetJSDev commented 1 year ago

The correct escaping of " is "". It doesn't use the JS \ character.

For example:

Excel generates the following CSV:

noquote,"""startquote","mid""quote","endquote"""

If you save that to a file and try to open in Excel, it will have the correct data.