Search code examples
htmljsonexcelhtml-tableimport-from-excel

Excel to HTML table


I'm new to web programming and the first project that i'm working on is a web site that allows the user to see information from an Excel file (which is updated daily). I started from converting the Excel file to JSON with the help of a Youtube tutorial and this library https://github.com/SheetJS/js-xlsx.

I have the information that i want converted to objects but I don't know how to use it to show a table in a website. Any suggestions?

This is my current code:

/* set up XMLHttpRequest */
  var url = "Teste.xlsx";
  var oReq = new XMLHttpRequest();
  oReq.open("GET", url, true);
  oReq.responseType = "arraybuffer";

  oReq.onload = function(e) {
    var arraybuffer = oReq.response;

    /* convert data to binary string */
    var data = new Uint8Array(arraybuffer);
    var arr = new Array();
    for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
    var bstr = arr.join("");

    /* Call XLSX */
    var workbook = XLSX.read(bstr, {
      type: "binary"
    });

    /* DO SOMETHING WITH workbook HERE */
    var first_sheet_name = workbook.SheetNames[0];
    //var address_of_cell = 'A1';
    /* Get worksheet */
    var worksheet = workbook.Sheets[first_sheet_name];
    XLSX.utils.sheet_to_json(worksheet);

  }

  oReq.send();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>
<html>

<head>
  <title>Test</title>
  <script src="xlsx.full.min.js"></script>

</head>

<body>
</body>

</html>


Solution

  • Think you're over-complicating things a bit.

    Excel files can be exported as html files and or you can EMBED the excel file into a html file in a number of ways.

    1. You could create a live excel file using office online Once the excel file is created , go to to the File menu, and choose Share. Embed using generated HTML.

    2. If you are not confined to excel, you could alternatively use an iframe with a "Google Sheets" document created with the data and choose the "Publish to the web" option in the sheet; an embedded google sheet will update to reflect updates.

    3. If you are really in a hurry you can convert your file into a HTML table using a tool like Tableizer but I wouldn't recommended this as a learning tool. (this is for future reference)

    Hope this helps