Search code examples
javascripthtmlxlsxxls

Can't figure out How to change the input file to an static folder file


I have a 'stolen' code here, which i want to change the input sector to a file in my folder on the server without uploading the file first. The problem is that I am a little bit bad in javascript to figure it out, how to change the code to do that. Thanks for any help.

<script src="jquery-2.1.4.min.js"></script>
<script lang="javascript" src="xlsx.full.min.js"></script>


<input type="file" id="input-excel" src="test.xslx"/>
<div id="wrapper">
</div>

<script>
  $('#input-excel').change(function(e){
  reader.readAsArrayBuffer(e.target.files[0]);
            reader.onload = function(e) {
                    var data = new Uint8Array(reader.result);
                    var wb = XLSX.read(data,{type:'array'});
                    //var htmlstr = XLSX.write(wb,{sheet:"Kondensatoren", type:'binary',bookType:'html'});
                    var htmlstr = XLSX.write(wb,{sheet:"Tabelle1", type:'binary',bookType:'html'});
                    $('#wrapper')[0].innerHTML += htmlstr;
            }
    });
</script>

Solution

  • Thx @Tallboy. Just for other newbies as me. The full code is.

    <script src="jquery-2.1.4.min.js"></script>
    <script lang="javascript" src="xlsx.full.min.js"></script>
    <div id="wrapper"></div>
    
    <script>
      var oReq = new XMLHttpRequest();
      oReq.open("GET", "test.xlsx", true);
      oReq.responseType = "arraybuffer";
    
      oReq.onload = function(oEvent) {
        var arrayBuffer = oReq.response;
        var data = new Uint8Array(arrayBuffer);
        var wb = XLSX.read(data,{type:'array'});
        var htmlstr = XLSX.write(wb,{sheet:"Kondensatoren", type:'binary',bookType:'html'});
        $('#wrapper')[0].innerHTML += htmlstr;
      };
      oReq.send();
    </script>