Is it possible to generate a CSV with multiple data? I have 2 tabs in which different type of question like general and advanced. After filling the form i want the export the data to one csv file with 2 Sheets. e.g. mydata.csv will be the file name and two sheets of general and advanced information.
Asked
Active
Viewed 4,287 times
5
-
1Not sure I well understood : do you know that a csv file is a plain text file which can't have sheets (even if it can be opened by spreadsheet applications) ? – Jean-Baptiste Rudant Dec 24 '15 at 06:44
-
you can have a look at this fiddle http://jsfiddle.net/terryyounghk/kpegu/ – subi_speedrunner Dec 24 '15 at 06:48
-
Possible duplicate of [Export to CSV using jQuery and html](http://stackoverflow.com/questions/16078544/export-to-csv-using-jquery-and-html) – Kunal Kakkad Dec 24 '15 at 06:50
-
I am not asking to export data to single file with single sheet. i am asking for multiple sheets in a single csv @KunalKakkad – panwar Dec 24 '15 at 07:04
-
@Jean-BaptisteRudant: Thanx...it means i can not have multiple sheets in a single csv. – panwar Dec 24 '15 at 07:06
1 Answers
1
You can do using below code
function concatCSVAndOutput(csvFilePaths, outputFilePath) {
const promises = csvFilePaths.map((path) => {
return new Promise((resolve) => {
const dataArray = [];
return csv
.parseFile(path, {headers: true})
.on('data', function(data) {
dataArray.push(data);
})
.on('end', function() {
resolve(dataArray);
});
});
});
return Promise.all(promises)
.then((results) => {
const csvStream = csv.format({headers: true});
const writableStream = fs.createWriteStream(outputFilePath);
writableStream.on('finish', function() {
console.log('DONE!');
});
csvStream.pipe(writableStream);
results.forEach((result) => {
result.forEach((data) => {
csvStream.write(data);
});
});
csvStream.end();
});
}
concatCSVAndOutput(['1.csv', '2.csv'], 'outputfile.csv');

Mustafa Poya
- 2,615
- 5
- 22
- 36

Hoks Vishu
- 63
- 4