Currently, I am working on extracting data from a web application built with Angular 6.
In my scenario, I have an array of strings where each string represents a line in a CSV format like this:
var csvLines = ['val1,val2\n', 'val3,val4\n'...];
After adding all the necessary data to the array, I display it in the console:
https://i.sstatic.net/KulBF.png Everything shows up correctly...
Now, my goal is to convert this data into a blob and download it as a .CSV file.
The downloading part works fine, but there seems to be an issue with the output format.
When I execute the following code:
const blob = new Blob([csvLines], {type: 'text/csv;encoding:utf-8'});
const reader = new FileReader();
reader.onload = () => {
console.log(reader.result);
};
reader.readAsText(blob);
I end up with this unexpected output.
NOTE: Notice the commas that are added to every line except the first one - this disrupts my CSV structure. https://i.sstatic.net/1j6lG.png
Could someone shed some light on why this occurs and provide suggestions on how to prevent these extra commas?
I've attempted creating the Blob using text/plain
as the MIME type and excluding the encoding, but the issue with the commas persists.