JSON到Excel转换在Nodejs中

我试图将大量的JSON数据转换为Excel,并尝试了几个模块下面是我的发现,如果有人使用更好的节点模块处理更多的数据,请让我知道,让我可以探索

json2xls

100000长度的JSON数组花了402574ms一旦我超过了200000它失败了这个错误FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory

节点XLS

长度为100000 JSON数组花了444578ms

我在Windows 7系统中使用8GB RAM,Intel Core i7,CPU @ 2.10Ghz – 2.70Ghz

首先把你的数据推到一个需要的列的临时数组中,然后把它转换成xls,我用下面的方法完成它:

 // use the below package to convert json to xls var json2xls = require('json2xls'); json.forEach(function(instance, indexx,record){ var tempArry = { 'ColoumnName1' : record[indexx].columnNameVlaue, 'ColoumnName2' : record[indexx].columnNameVlaue, 'ColoumnName3' : record[indexx].columnNameVlaue, 'ColoumnName4' : record[indexx].columnNameVlaue } jsonArray.push(tempArry); }); //this code is for sorting xls with required value jsonArray.sort(function(a, b) { return parseFloat(b.ColoumnName4) - parseFloat(a.ColoumnName4); }); var xls = json2xls(jsonArray); fs.writeFileSync('yourXLName.xlsx', xls, 'binary'); 

不要试图将所有的数据添加到Excel文件中,使用文件中的特定列来保存。

我需要从JSON文件中写入特定的数据到Excel工作表。 例如,我需要在excel表格的“Account”列中单独填写“Account”(来自JSON)的详细信息。 我的示例JSON数据

 { "Details": [ { "FirstName": "FName", "LastName": "LName", "Account": "598975587989" }, ] }