【问题标题】:sails:How can i read excel file data into json format帆:如何将excel文件数据读成json格式
【发布时间】:2015-08-25 11:01:38
【问题描述】:

上传 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格式

【问题讨论】:

    标签: jquery node.js sails.js waterline


    【解决方案1】:

    试试xlsx-rows

    简单易行:)

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

    【讨论】:

    • 谢谢,但我也需要阅读 xls 文件。这可能吗?如果是意味着如何?
    猜你喜欢
    • 2017-07-12
    • 2019-06-09
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多