simple-excel-js icon indicating copy to clipboard operation
simple-excel-js copied to clipboard

Parsing CSV Issue: New lines within quotes not parsed correctly

Open stripathi669 opened this issue 4 years ago • 1 comments

Hi

I am facing an issue where if a cell entry is a multi-line entry, it is not being read / parsed correctly.

Consider a CSV entry like this:

Client Name,Display Name,Phone Number,Email,Notes
ACBDE,-,111,[email protected],"Part 1
Part 2
Part 3
part 4"

The correct parsing is:

Row 1 -> Client Name,Display Name,Phone Number,Email,Notes
Row 2 -> ABCDE,-,111,[email protected],"{multi line entry: Part1\nPart 2\nPart 3\n Part 4}"

But right now it is being parsed as:

Row 1 -> Client Name,Display Name,Phone Number,Email,Notes
Row 2: ABCDE,-,111,[email protected], Part 1
Row 3: Part 2
Row 4: Part 3 
Row 5: Part 4

stripathi669 avatar Feb 01 '21 11:02 stripathi669

I suspect this is due to Regex.LINEBREAK which does not ignore linebreaks if they are within quotes.

Relevant discussion here: https://stackoverflow.com/questions/10407697/split-a-csv-string-by-line-skipping-newlines-contained-between-quotes

stripathi669 avatar Feb 01 '21 11:02 stripathi669