Change CSV headers while processing papaparse
Asked Answered
R

2

10

Is it possible to change the headers of a "csv" file to uppercase during the process performed by papa.parse using JavaScript?!

Thanks in advance.

Rajasthan answered 31/1, 2016 at 12:39 Comment(0)
R
14
beforeFirstChunk: function(chunk) {
                    var rows = chunk.split( /\r\n|\r|\n/ );
                    var headings = rows[0].toUpperCase();
                    rows[0] = headings;
                    return rows.join("\r\n");
                },

supporting 'beforeFirstChunk' solved me this issue, nevertheless if you use 'worker: true' inside your configuration it will trigger an exception, looks like a known bug.

Rajasthan answered 8/2, 2016 at 8:29 Comment(0)
U
3

As of version 5.0, PapaParse now has transformHeader, which is

A function to apply on each header. Requires header to be true. The function receives the header as its first argument. Only available starting with version 5.0.

You can see an example at Using PapaParse transformHeader to remove whitespace from headers?.

Uppity answered 27/2, 2020 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.