簡體   English   中英

如何在nodejs中使用exceljs將所有數組元素寫入excel文件

[英]how to write all array elements to excel file using exceljs in nodejs

我有一個問題。我想在nodejs中使用exceljs將所有數組元素寫入excel文件。

我的數組就像這個數組圖像

並且比我想寫excel文件。 例如excel圖像

那么我該怎么做呢? 感謝幫助..

對於這種必須將數據數組放入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
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM