我想将json数据转换为Xlsx文件并将其保存在文件夹中。 我一直在尝试使用icg-json-to-xlsx模块,但直到现在我一直无法使用它。 我的代码如下所示:将Json转换为Xlsx文件
jsonXlsx = require('icg-json-to-xlsx');
filename = path.join('./files', "output.xlsx");
outputFile = jsonXlsx(filename, result) //result contains json data
console.log(outputFile);
,但我得到这个错误
outputFile = jsonXlsx(filename, result)
^
TypeError: Property 'jsonXlsx' of object # is not a function
从MongoDB中获取数据: 在路线:
router.get('/', function(req, res, next) {
fileController.getAll(function(err, result){
if(err){
res.send(500,err);
}
// res.json(result);
var data = result;
在控制器:
FileController.prototype.getAll = function(callback){
File.find({}, {_id: false, id: true, name: true, status: true}, function(err, file){
if(err) {
return callback(err);
} else {
if (!file) {
return callback('file not found');
}
}
callback(null, file);
}
)};
感谢您的信息,但这个问题已经解决:) – ishakya 2014-12-17 04:58:18