In a project you need to read the contents of Excel, of course, Excel is formatted, the format is read to the first line as the property (Title)
For example, the following Excel
Language |
Detil |
En |
中文版 |
cn |
Chinese |
Jp |
Japanese |
The Excel resolves to: Mode 1
Of course it can be resolved as follows: Mode 2
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////
Body Start:
First you need to refer to Xlsx.full.min.js to provide links: https://pan.baidu.com/s/1o7HK6vw
First page add input type=file to get the file
< input type = "File" onchange = "Importexcel (this)" class = "Filter_input Form-control" />
The functions inside the onchange are as follows:
varWb//read the completed datavarRABS =false;//whether to read the file as a binary stringfunctionImportexcel (obj) {//Importif(obj.files.length==0) {return; } Const Importfile_maxsize= 10*1024;//Here you can customize the control of the import file size varsuffix = obj.files[0].name.split (".") [1] $(' #_file_path '). Val (obj.files[0].name); if(Suffix! = ' xls ' && suffix! = ' xlsx ') {layer.msg ("Only support excel!"); return; } if(obj.files[0].size/1024 > Importfile_maxsize) {layer.msg ("The file can not be over 10MB"); return; } varf = obj.files[0]; varReader =NewFileReader (); Reader.onload=function(e) {data=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 varA=WB. Sheetnames[0]; varb=WB. Sheets[a]; //content is mode 2 data=XLSX.utils.sheet_to_json (b); //content as Way 1 if(!data| | data== "") {Layer.closeall (' Loading '); Layer.msg ("The file is empty choose another file!"); return; }
//Perform the processing of the parsed data here
//var compile_result=batch_compile (data);
//drawtable (compile_result);
}; if(RABS) {reader.readasarraybuffer (f); } Else{reader.readasbinarystring (f); } 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; }}
About jquery Read the contents of an Excel file in XLS xlsx format