Native jsActiveXObject to get the value in execl _ javascript skills

Source: Internet
Author: User
If you use native js to obtain the values in execl, you may not have many friends. The following is a good method to implement it using ActiveXObject, if you are interested, do not miss it. Today, a programmer gave an excel table containing more than one hundred pieces of data, let me copy data one by one to the corresponding function, such as put ("gaga1", "gaga2"). In this case, I have to copy the data more than one hundred times, fuck. I will say that you can read it in java! He said that it would take more than half an hour to use java, So I thought about fuck. You don't know much about java! At this time, I am in the heart of a few lines of grass in the Pentium !!!!!!

So I went to a js method to read the data in the excel file. It didn't take half an hour to modify it! It's fuck!

The data in execl is probably like this:

The output is as follows:

Js source code:

The Code is as follows:


Function readThis (){
Var tempStr = "";
Var filePath = document. all. upfile. value;
Var oXL = new ActiveXObject ("Excel. application ");
Var oWB = oXL. Workbooks. open (filePath );
OWB. worksheets (1). select ();
Var len = 100; // The number of data records to be retrieved
Var oSheet = oWB. ActiveSheet;
Try {
For (var I = 1; I <= len; I ++ ){
TempStr + = ("put (\" "+ oSheet. cells (I, 1 ). value + "\", \ "" + oSheet. cells (I, 2 ). value + "\"); ") +"
"; // 1 and 2 represent the first and second columns respectively
}
} Catch (e ){
Document.all.txt Area. innerHTML = tempStr;
}
Document.all.txt Area. innerHTML = tempStr;
OXL. Quit ();
CollectGarbage ();
}


Html source code:

The Code is as follows:





Because ActiveXObject only supports IE, you can only run it using IE. Now, I want to use this method!

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.