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!