I am trying to export a valid csv on a JS client application. I have a function that converts arrays to a csv string by adding commas between each item and a line terminator between each row of arrays. I am positive that my function works well (atleast with formatting). However when it's given more than 160 rows, it just stops appending. What might be wrong? Is there a limit to how long a string can be? A limit to how long a csv generated client side can be?
My CSV header is: data:text/csv;charset=utf-8,
[Edit] I think it actually is some sort of a limit that the browser set. Not sure if it's with how long a CSV file can be, or how long a string can be. Any idea how I can get around this limitation?
[Edit] Code:
const BASE_CSV_HEADER = 'data:text/csv;charset=utf-8'
const stringify = text => {
let retval
try {
retval = text.toString()
} catch(e) {
retval = text
}
return typeof retval === 'string' ? retval || ' '
}
const stripForCSV = (row) => {
let newRow = []
row.forEach((text) => {
text = stringify(text)
newRow.push(text.replace(/,/g, '.')) // to avoid comma clashes
})
return newRow
}
const arraysToCsv = (arrays) => {
let csv = ''
arrays.forEach(row => {
row = stripForCSV(row)
csv += row.join(',');
csv += "\n";
})
return csv
}
const getCSV (jsObject) => {
const arrays = convertJsObjectToArrayOfArrays(jsObject)
const csv = arraysToCsv(arrays)
return BASE_CSV_HEADER + csv // Removed encodeURI
}
[EDIT]
Solved!!
As mentioned here: Export HTML table to csv in google chrome browser
I had to change the download type to Blob.