【发布时间】:2015-02-01 22:38:06
【问题描述】:
我正在尝试将 json 数据转换为 Xlsx 文件并将其保存在文件夹中。 我一直在尝试使用 icg-json-to-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);
}
)};
【问题讨论】: