美文网首页
Nodejs 将excel转成json

Nodejs 将excel转成json

作者: Fat_Bone | 来源:发表于2018-06-30 19:02 被阅读0次
    1. 先安装一个工具
      根据你的excel文件格式,使用相应的工具哦
    npm install xlsx-to-json-lc --save
    npm install xls-to-json-lc --save
    
    1. 实现代码
      var exceltojson = require("xls-to-json-lc"); //或者xlsx-to-json-lc,取决于你的文件名。
      exceltojson({
        input: "pass the input excel file here (.xls format)" //要转换的excel文件,如"/Users/chenyihui/文件/matt/1_2.xlsx"
        output: "if you want output to be stored in a file" //输出的json文件,可以不写。如"./yeap.json"
        sheet: "sheetname",  // 如果有多个表单的话,制定一个表单(excel下面那些标签),可以忽略
        lowerCaseHeaders:true //所有英文表头转成大写,可以忽略
      }, function(err, result) {
        if(err) {
          console.error(err);
        } else {
          console.log(result);
          //result will contain the overted json data
        }
      });
    

    相关文章

      网友评论

          本文标题:Nodejs 将excel转成json

          本文链接:https://www.haomeiwen.com/subject/rccxuftx.html