我有问题..我想在nodejs中使用exceljs将所有数组元素写入excel文件。例如;
我的数组就像这样array image
而不是我想写excel文件。 例如excel image
那我怎么能这样做呢?谢谢你的帮助......
答案 0 :(得分:0)
对于你必须将数据数组放入Excel或CSV文件的这种要求,我在我的情况下使用了fast-csv
所以我正在编写代码。希望这会对你有所帮助。
您可以使用以下代码:
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
});