简体   繁体   中英

Javascript parse XLS - XLSX not defined

I have been trying to use sheetJS and follow examples that completely work in jsfiddle, however I cannot get to work when creating a new js file. I have tried multiple browswers, but keep getting the same error "XLSX is not defined"

I have tried this Excel to JSON javascript code? and wanted to ask on there but needed 50 rep to leave a comment.

Here is the code snippet and am including the following files in this order: shim.js, jszip.js,xlsx.js

    var oFileIn;

$(function() {
    oFileIn = document.getElementById('xlf');
    if(oFileIn.addEventListener) {
    console.log("if hit")
    oFileIn.addEventListener('change', filePicked, false);
}
    $("#xlf").on("change",function(oEvent){
        console.log("jqiey workd?")
        filePicked(oEvent)
    })
});
function filePicked(oEvent) {
    // Get The File From The Input
    var oFile = oEvent.target.files[0];
    var sFilename = oFile.name;
    // Create A File Reader HTML5
    var reader = new FileReader();

   // Ready The Event For When A File Gets Selected
   reader.onload = function(e) {
   var data = e.target.result;
   var cfb = XLSX.read(data, {type: 'binary'});
   console.log(cfb)
   cfb.SheetNames.forEach(function(sheetName) {
    // Obtain The Current Row As CSV
    var sCSV = XLS.utils.make_csv(cfb.Sheets[sheetName]);   
    var oJS = XLS.utils.sheet_to_json(cfb.Sheets[sheetName]);   

    $("#my_file_output").html(sCSV);
    console.log(oJS)
    $scope.oJS = oJS
});
};

I have tried numerous examples, this is just the only one I came across that worked on jsfiddle. The same error occurs if it is XLS or XLSX...

In other examples such as the one provided by sheetJS it has var X = XLSX; right under the script segment, and will automatically get error that XLSX is not defined on that line.

Anyone come across this, or know what the issue is?

-Thanks!!!

The included files with the project weren't correct. The project had a corrupt js file. I fixed it by manually adding all sheet project download folder and replacing files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM