Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Papa Parse giving extra empty row when parsing CSV file

Just found Papa Parse home page, trying to learn to use it. Overall, things look pretty nice, easy to use.

I created a super-simple worksheet in Excel: three columns, first row being a header row naming the columns, and then three data rows, saved the spreadsheet in CSV format. opened that CSV file, it has 4 lines, just as I would expect.

Created a web page to run Papa.parse, dumped results to console.log, just like the example:

(5) [Array(3), Array(3), Array(3), Array(3), Array(1)]
0 : (3) ["Column A", "Column B", "Column C"]
1 : (3) ["Row 1, Col A", "Row 1, Col B", "Row 1, Col C"]
2 : (3) ["Row 2, Col A", "Row 2, Col B", "Row 2, Col C"]
3 : (3) ["Row 3, Col A", "Row 3, Col B", "Row 3, Col C"]
4 : [""]

I'm quite happy to see my data here, laid out as I would expect except for the 5th array there. That just seems "extra", "spurious", "wrong".

Not a big deal, certainly - I can deal with that. But I'm guessing that the extra array with an empty string isn't really "by design" is it? Why not just give the first 4 arrays?

For reference, here is the file input on my web page:

<input type="file" id="csvFile" oninput="readCsvFile('csvFile')">

And here is my callback function that gave the data above:

function readCsvFile(fileElId) {
    var
        fileEl = document.getElementById(fileElId),
        csvFile = fileEl.files[0];

    // Parse local CSV file
    Papa.parse(csvFile, {
        complete: function(results) {
            console.log("Finished:", results.data);
        }
    });
}

Anybody else seeing similar behavior? Does this qualify as a bug, or is there some good reason (i.e., documented reason?) to have that last, empty string array?

Thanks! ;)

like image 541
user1441004 Avatar asked Jun 30 '18 00:06

user1441004


1 Answers

This is an open issue on Papa Parse's Github repo. skipEmptyLines: true is noted as a workaround.

like image 138
AuxTaco Avatar answered Oct 11 '22 07:10

AuxTaco