The above is the whole content of this article PHP through the Phpexcel import Excel table to MySQL database Simple example, I hope that everyone's learning is helpful. Related recommendations:
As shown below:
<?phpdefine (' Base_url ', Realpath (dirname (__file__))); Require_once Base_url. '/phpexcel/phpexcel.php ';//The address of the//excel file that introduced the Phpexcel class file $excel_fiel_path = './phpexcel.xls '; $PHPExcel = new Phpexcel () ;//Instantiate Phpexcel Tool class//parse file gets the suffix to determine whether it is version 2007 or 2003$extend = PathInfo ("./". $excel _fiel_path); $extend = Strtolower ($extend [" Extension "]); Determine the xlsx version, if it is the 2007 version of XLSX, otherwise it is 2003if ($extend = = "xlsx") {$PHPReader = new phpexcel_reader_excel2007 (); $PHPExcel = $PHPReader->load ("./". $excel _fiel_path);} else{$PHPReader = new Phpexcel_reader_excel5 (); $PHPExcel = $PHPReader->load ("./". $excel _fiel_path);} /* The second method */$objWorksheet = $PHPExcel->getactivesheet (); $highestRow = $objWorksheet->gethighestrow (); Echo ' highestrow= '. $highestRow; echo "<br>" $highestColumn = $objWorksheet->gethighestcolumn (); $ Highestcolumnindex = phpexcel_cell::columnindexfromstring ($highestColumn);//Total number of columns echo ' highestcolumnindex= '. $ Highestcolumnindex;echo "<br>"; $headtitle =array (); for ($row = 2; $row <= $highestRow, $row + +) {$strs =array (); Note that the number of columns in the Highestcolumnindex index starts at 0 for ($col = 0; $col < $highestColumnIndex; $col + +) {$strs [$col] = $objWorksheet Getcellbycolumnandrow ($col, $row)->getvalue (); }//todo//Connect MySQL, write}
The above is the whole content of this article, I hope that everyone's study has helped.