Reference Blog: http://www.jianshu.com/p/74d405940305
GitHub Address:Sheetjs /js-xlsx
JS Introduction
<script type= "Text/javascript" src= "~/content/js-xlsx/xlsx.full.min.js" ></script>
Read method
/*FileReader A total of 4 reading methods: 1.readAsArrayBuffer (file): Read the file as Arraybuffer. 2.readAsBinaryString: Reads a file as a binary string 3.readAsDataURL (file): reads the file as data URL 4.readAsText (file, [enc Oding]): reads the file as text, encoding the default value is ' UTF-8 '*/ varWb//read the completed data varRABS;//whether to read the file as a binary string functionFixdata (data) {//File Flow binarystring varo = "", L= 0, W= 10240; for(; l < data.bytelength/w; ++l) O + = String.fromCharCode.apply (NULL,NewUint8array (Data.slice (L * W, l * w +W))) ; o+ = String.fromCharCode.apply (NULL,NewUint8array (Data.slice (L *W))) ; returno; } functionImportf (obj) {//Import if(!obj.files) {return; } varf = obj.files[0]; varReader =NewFileReader (); Reader.onload=function(e) {vardata =E.target.result; if(RABS) {WB= Xlsx.read (Btoa (Fixdata (data)), {//Manual ConversionsType: ' Base64 ' }); } Else{WB=Xlsx.read (data, {type:' Binary ' }); } //WB. Sheetnames[0] is the name of the first sheet to get sheets //WB. Sheets[sheet name] Gets the first sheet data //document.getElementById ("Demo"). InnerHTML = Json.stringify (XLSX.utils.sheet_to_json (WB). SHEETS[WB. Sheetnames[0])); varJsonstr = json.stringify (XLSX.utils.sheet_to_json (WB). SHEETS[WB. Sheetnames[0]));//Get JSON string varJsonobj = Json.parse (JSONSTR);//convert to JSON object varTojsonobj = [];//splicing JSON object Arrays for(vari = 0; i < jsonobj.length; i++) { varItem = Itemobj (Jsonobj[i], i);//Stitching JSON ObjectsTojsonobj.push (item); } $(' #list '). Bootstraptable (' Load ', Tojsonobj); }; if(RABS) {reader.readasarraybuffer (f); } Else{reader.readasbinarystring (f); } }
jquery Open Source Component--js-xlsx excle Import