0

I have a problem.. I want to write all array elements to excel file using exceljs in nodejs.. For example;

My array is like this array image

and than I want to write excel file. For example excel image

So how can I do this just like that.? Thanks for help..

Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75

1 Answers1

0

For such kind of requirements where you have to put the array of data into Excel or CSV file, I have used fast-csv in my case so I am writing code for that. Hope this will helps you. .

You can use the following code:

var fs  = require('fs'); // using npm install fs module on application
var csv = require("fast-csv"); // I used this module in my case

var csvFileName = 'path of folder/file.csv'; 
var stream = fs.createReadStream(csvFileName); //reads the file
var headings = [];
var full = [];

headings.push('head1','head2','head3');

full.push(headings);

var csvStream = csv.createWriteStream({headers: true}),
           ws = fs.createWriteStream(file_location);

csv.write(full, {headers: true}).pipe(ws);
ws.on("finish", function(){
 response.redirect('/enriched'); // response is response parameter of your callback function
 // redirect where you wants
});
Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75