[英]how to convert the json file into excel using node.js considering twitter data in mongodb
var json2csv = require('json2csv'); json2csv({data: someJSONData, fields: ['screen_name', 'statuses_count', 'location']}, function(err,csv) { if (err) console.log(err); console.log(csv); }); var json = [ { "screen_name: "Doug_E_Stile"", "statuses_count": 1546, "location": "Maryland"" }, { "screen_name": "cthxidm",, "statuses_count": 339, "location": "peru manyas¿", }, { "screen_name": ""jiiiiimarjoh", "statuses_count": 4205,, "location": "South Cotabato, Philippines" } ]; json2csv({data: json, fields: ['screen_name', 'statuses_count', 'location']}, function(err, excel) { if (err) console.log(err); fs.writeFile('file.csv', csv, function(err) { if (err) throw err; console.log('file saved'); }); });
Looks like you are using a variable named csv
, but the name of your function parameter is excel
. 看起来您使用的是名为csv
的变量,但函数参数的名称是excel
。 It should be: 它应该是:
fs.writeFile('file.csv', excel, function(err) {
instead of 代替
fs.writeFile('file.csv', csv, function(err) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.