Started PHP for some time, the recent I used some of the techniques to summarize, convenient later can be used directly:
Header"content-type:text/html; Charset=utf-8 ");require_once' phpexcel.php ';require_once' phpexcel\iofactory.php ';require_once' phpexcel\reader\excel2007.php ';$uploadfile=' data.xlsx ';$objReader= Phpexcel_iofactory::createreader (' Excel2007 ');/*excel5 for 2003 excel2007 for 2007*/$objPHPExcel=$objReader->load ($uploadfile);//excel Path$sheet=$objPHPExcel->getsheet (0);$highestRow=$sheet->gethighestrow ();//Total number of rows obtained$highestColumn=$sheet->gethighestcolumn ();//Get total number of columns/ * Method One * /$strs=Array(); for($j=1;$j<=$highestRow;$j++){//Start reading data from the first line/ * Log off the previous line to read the data * /unset($str);unset($strs); for($k=' A ';$k<=$highestColumn;$k++){//Read data from column A//measured in Excel, if the value of a cell contains | | | | | | The imported data will be empty$str.=$objPHPExcel->getactivesheet ()->getcell ("$k $j")->getvalue ().'||||||';//Read cells}//explode: Function splits a string into arrays. $strs= Explode ("||||||",$str);$sql="INSERT into Te () VALUES (' {$strs [0]} ', ' {$strs [1]} ', ' {$strs [2] } ', ' {$strs [3]} ', ' {$strs [4]} ')";Echo$sql.'
'; }/ * Method Two "recommended" * /$objWorksheet=$objPHPExcel->getactivesheet ();$highestRow=$objWorksheet->gethighestrow ();//Total number of rows obtained$highestColumn=$objWorksheet->gethighestcolumn ();$highestColumnIndex= Phpexcel_cell::columnindexfromstring ($highestColumn);//Total number of columns for($row=1;$row<=$highestRow;$row++) {$strs=Array();//Note the number of columns in the Highestcolumnindex index starting from 0 for($col=0;$col<$highestColumnIndex;$col++) {$strs[$col] =$objWorksheet->getcellbycolumnandrow ($col,$row)->getvalue (); } print_r ($strs); }?>
Result: Array (4) {[0]=> string (10) "Software 1 Shift" [1]=> string (7) "31" [2]=> string (7) "Hello 1" [3]=> string (0) ""} Array (4 {[0]=> string (10) "Software 2 Class" [1]=> string (7) "32" [2]=> string (7) "Hello 2" [3]=> string (0) ""} Array (4) {[0]=&G T String (10) "Software Class 3" [1]=> string (7) "33" [2]=> string (7) "Hello 3" [3]=> string (0) ""} Array (4) {[0]=> string (10) "Software class 4" [1]=> string (7) "34" [2]=> string (7) "Hello 4" [3]=> string (0) ""} Array (4) {[0]=> string (10) "Software 5 class" [1 ]=> string (7) "35" [2]=> string (7) "Hello 5" [3]=> string (0) ""} Array (4) {[0]=> string (10) "Software 6 class" [1]=> str ING (7) "Zhang 36" [2]=> string (7) "Hello 6" [3]=> string (0) ""} Array (4) {[0]=> string (10) "Software 7 Class" [1]=> string (7) "Zhang San 7 "[2]=> string (7)" Hello 7 "[3]=> string (0)" "} Array (4) {[0]=> string (10)" Software 8 class "[1]=> string (7)" 38 "[2]=> ; String (7) "Hello 8" [3]=> string (0) ""} Array (4) {[0]=> string (10) "Software 9 class" [1]=> string (7) "39" [2]=> string (7) "Hello 9" [3]=> striNg (0) ""}
Above is my use of phpexcel code, I know, there are many online, but their own summary under the future can be quickly found, in also do not Baidu;
Phpexcel Bag
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the preliminary use of Phpexcel, including the content of Excel, I hope that the PHP tutorial interested in a friend helpful.