// save to CSV
var csv = document.getElementById('a');
var csvContent = new Array();
csvContent.push(["COL_A","COL_B","COL_C"]);
var fileName = "file.csv";
var blob = new Blob(["\ufeff", csvContent]);
var url = URL.createObjectURL(blob);
csv.href = url;
csv.setAttribute('download', fileName);
csv.click();
// load CSV file
..
var lines = loadedCsvFile.split(/\r\n|\n/);
var result = [];
var headers = lines[0].split(",");
for(var i=0;i<lines.length;i++){
var obj = {};
var currentLine = lines[i].split(",");
for(var j=0;j<headers.length;j++){
obj[headers[j]] = currentLine[j];
}
result.push(obj);
}
this is my csv save/load code.
But, this code can use only first sheet.
how can I use second sheet? I should be very grateful to you if you might help me.
I assume you're talking about a CSV from Excel (or the likes) which 'had' multiple sheets?
CSVs don't use the sheet concept, they're are saved as a flat file. You will either need to save each sheet as a CSV individually and read separately, or concatenate the sheets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.