Tool to convert Excel to Json

Asked

Viewed 2,192 times

1

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

1 answer

2


Body of html:

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

Head of Html:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="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);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.