帆:我怎样才能读取Excel文件数据到JSON格式

我想上传Excel文件后,读取本地文件夹中的excel文件。

var fs = require('fs'); uploadFile.upload ({ // don't allow the total upload size to exceed ~10MB maxBytes: 10000000, saveAs: function(uploadFile, cb) {cb(null,Date.now()+uploadFile.filename ); },dirname: '../../assets/uploads' },function whenDone(err, uploadedFiles) { if (err) { console.log("error"); return res.negotiate(err); } // If no files were uploaded, respond with an error. if (uploadedFiles.length === 0) { return res.badRequest('No file was uploaded'); } else { var fd = uploadedFiles[0].fd; console.log(fd); fs.readFile(fd, 'utf8', function (err, data) { console.log(data); }); } 

如果是文本文件意味着我会成功读取,但在excel文件的情况下,我不能够读取excel数据。

也需要将这个excel文件数据转换成json格式

尝试xlsx行

简单而简单:)

 var fd = uploadedFiles[0].fd; var rows = require('xlsx-rows')(fd); rows = rows.slice(1); rows.forEach(function(obj){ // do something.... });