2017-11-14 22 views
0

私はsampledata.xlsxと呼ばれるExcelシートをjsonとconsole.logに変換してこのデータを印刷しました。 this docの助けを借りてexcel(.xlsx)ファイルをJSONに変換する

server.js 
 

 

 
var xlsx2json = require('xlsx2json') 
 

 

 
xlsx2json(
 
    'sampledata.xlsx', 
 
{ 
 
    dataStartingRow: 2, 
 
    mapping: { 
 
     'name': 'B',//name 
 
     'sku': 'C',//unit price   //sku 
 
     'quantity': 'D',//quantity 
 
     
 
    } 
 
}).then(jsonArray => { 
 
    // [ 
 
    //  {"col_1": "Barton LCC", "col_2": "30", "col_3": "86.69"} 
 
    // ] 
 
    
 
//console.log(jsonArray); 
 
});

。 私がここでやりたいことは、私のsampledata.xlsxファイルにフラット、アドレス、価格などのデータがあります。私はすでにどのフィールドが存在しているのか分かりません。Excelシート console.logにすることができます。これを行う方法はありますか?

答えて

0
npm install xlsx-to-json-lc --save 
npm install xls-to-json-lc --save 

var exceltojson = require("xls-to-json-lc"); 
 
    exceltojson({ 
 
    input: "pass the input excel file here (.xls format)" 
 
    output: "if you want output to be stored in a file" 
 
    sheet: "sheetname", // specific sheetname inside excel file (if you have multiple sheets) 
 
    lowerCaseHeaders:true //to convert all excel headers to lowr case in json 
 
    }, function(err, result) { 
 
    if(err) { 
 
     console.error(err); 
 
    } else { 
 
     console.log(result); 
 
     //result will contain the overted json data 
 
    } 
 
    });

+0

あなたは私がJSONとして私に出力を与え、私が持っているファイルは、あなた.xlsx.Theコードの拡張子を持つにconsole.log(jsonArray)を持って見ることができれば私は試して、それはサポートされていないファイルのエラーを与える。 – Suresh

+0

var exceltojson = require( "xlsx-to-json-lc"); .xlsxファイルタイプの拡張のために必要となる可能性があります –

関連する問題