Node.js中的JSON至Excel转换 [英] JSON to Excel convertion in Nodejs
问题描述
我正在尝试将大量json数据转换为excel,并尝试了几个模块 以下是我的发现,如果有人使用更好的节点模块来处理更多数据,请告诉我,以便我进行探索
I'm trying to convert large amount of json data to excel and tried couple of modules Below are my findings, if anyone used better node module which handle more data please let me know so that i can explore
json2xls
长度为100000
的JSON数组占用了402574ms
一旦我超过了200000
,它就会失败并显示此错误FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
JSON array with 100000
length took 402574ms
once i exceeded to 200000
it failed with this error FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
node-xls
长度为100000
的JSON数组花费了444578ms
JSON array with 100000
length took 444578ms
我在具有8GB RAM,Intel Core i7,CPU @ 2.10Ghz-2.70Ghz的Windows 7系统中尝试过此操作
I tried this in windows 7 system with 8GB RAM, Intel Core i7, CPU @ 2.10Ghz - 2.70Ghz
推荐答案
如果它是一个nodejs项目,则执行此操作,
If its a nodejs project then do this,
const xlsx = require("xlsx")//npm install xlsx
const fs = require("fs")//npm install fs
var rawFile = fs.readFileSync("./datas.json")//dir of your json file as param
var raw = JSON.parse(rawFile)
var files = []
for (each in raw){
files.push(raw[each])
}
var obj = files.map((e) =>{
return e
})
var newWB = xlsx.book_new()
var newWS = xlsx.utils.json_to_sheet(obj)
xlsx.utils.book_append_sheet(newWB,newWS,"name")//workbook name as param
xlsx.writeFile(newWB,"Sample-Sales-Data.xlsx")//file name as param
这篇关于Node.js中的JSON至Excel转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!