2017-11-14 3 views
0

Ich habe Excel-Blatt namens sampledata.xlsx, die ich in json und console.log konvertiert, um diese Daten zu drucken.konvertieren Excel (.xlsx) Datei zu 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); 
 
});

mit Hilfe von this doc. Was ich hier tun möchte, ist, in meiner sampledata.xlsx Datei habe ich mehr Daten wie Wohnung, Adresse, Preis usw. hier weiß ich nicht, welche Felder in meinem Excel Blatt vorhanden sind, aber ich will all das zu sei console.log.Wie könnte ich das tun? Gibt es irgendeinen Weg dies zu tun?

Antwort

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

, wenn Sie sehen, ich habe console.log (jsonArray), die mir Ausgabe als json und die Datei gibt, die ich haben die Erweiterung von .xlsx.The Code hat die Sie vorausgesetzt, ich habe es versucht und es gibt Fehler der nicht unterstützten Datei. – Suresh

+0

var exceltojson = require ("xlsx-to-json-lc"); kann für die Dateierweiterung .xlsx benötigt werden –

Verwandte Themen