About jquery Read the contents of an Excel file in XLS xlsx format

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.