Tool to convert Excel to Json [duplicate]

1

I have an excell table and I need to generate a graph with Charts.js which uses json to mount the database. So how can I convert an excel table with 50 rows and 10 columns into JSON data.

    
asked by anonymous 07.04.2016 / 15:35

1 answer

2

Body of html:

<label> Arquivo do excel: </label><input id="excelfile" />
<div id="output"></div>

Html Head:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/xls/0.7.4-a/xls.js" type="text/javascript></script>

Your Javascript:

var oFileIn;

$(function() {
    oFileIn = document.getElementById('my_file_input');
    if(oFileIn.addEventListener) {
        oFileIn.addEventListener('change', filePicked, false);
    }
});


function filePicked(oEvent) {
    var oFile = oEvent.target.files[0];
    var sFilename = oFile.name;
    var reader = new FileReader();

    reader.onload = function(e) {
        var data = e.target.result;
        var cfb = XLS.CFB.read(data, {type: 'binary'});
        var wb = XLS.parse_xlscfb(cfb);
        wb.SheetNames.forEach(function(sheetName) {
            var sCSV = XLS.utils.make_csv(wb.Sheets[sheetName]);   
            var oJS = XLS.utils.sheet_to_row_object_array(wb.Sheets[sheetName]);   

            $("#output").html(sCSV);
            console.log(oJS)
        });
    };

    reader.readAsBinaryString(oFile);
}
    
08.04.2016 / 00:39