First of all, go to phpexcel official website to download Phpexcel, the official address is http://phpexcel.codeplex.com/. I'm under 1.8.0 version of. After decompression found still pretty big, there are more than 10 m, do not know the other version is not will be small point.
Put the extracted phpexcel files under the thinkphp Vender folder (specifically for third-party libraries), such as
Next, create the Excel transform array class and put it in the Thinkphp\extend\library\org\util directory
Classexceltoarrary {Publicfunction__construct() {Vendor ("PHPExcel.Classes.PHPExcel");Introduce the Phpexcel class (note the path, do not know the path can see the book) Vendor ("PHPExcel.Classes.PHPExcel.IOFactory");Introduce the Phpexcel class (note the path)}PublicfunctionRead($filename,$encode,$file _type) {if (Strtolower ($file _type) = =' XLS ')Determine whether the Excel table type is 2003 or $ {Vendor ("PHPExcel.Classes.PHPExcel.Reader.Excel5");Introducing the Phpexcel class (note the path)$objReader = Phpexcel_iofactory::createreader (' Excel5 '); }ElseIf (Strtolower ($file _type) = =' xlsx ') {Vendor ("PHPExcel.Classes.PHPExcel.Reader.Excel2007");Introducing the Phpexcel class (note the path)$objReader = Phpexcel_iofactory::createreader (' Excel2007 '); }$objReader->setreaddataonly (true);$objPHPExcel =$objReader->load ($FILENAME);$objWorksheet =$objPHPExcel->getactivesheet ();$highestRow =$objWorksheet->gethighestrow ();$highestColumn =$objWorksheet->gethighestcolumn ();$highestColumnIndex = phpexcel_cell::columnindexfromstring ($highestColumn); $excelData = array (); for ( $row = 1; $row <= $highestRow; $row + +) {for ( $col = 0; $col < $highestColumnIndex; $col + +) { $excelData [ $row] = (string) $objWorksheet->getcellbycolumnandrow ( $col, $row)->getvalue (); }} return $excelData;}
Details Portal: http://blog.csdn.net/walle0513/article/details/47129619
ThinkPHP3.1.3 importing MySQL database from Excel table using phpExcel1.8.0 implementation data