1<?PHP2 //Phpexcel Read the import Excel data into the database (2003,2007 generic) using the method:3 /////Use the Excel2array () method to store data from an Excel table in an array and save the data into the database from the traversal of the two-dimensional array4 require_once"./phpexcel.class.php";5 require_once"./phpexcel/cell/datatype.php";6 require_once"./phpexcel/iofactory.php";7 /**8 * Store data from an Excel table in an array9 * @param string $filename file nameTen * @return Array One */ A functionExcel2array ($filename){ - $ext=PathInfo($filename, pathinfo_extension);//get file suffix name - if($ext= = "XLS"){ the $objReader= Phpexcel_iofactory::createreader (' Excel5 '); - } - if($ext= = "Xlsx"){ - $objReader= Phpexcel_iofactory::createreader (' Excel2007 '); + } - + $objReader->setreaddataonly (true); A $objPHPExcel=$objReader->load ($filename); at $objWorksheet=$objPHPExcel-Getactivesheet (); - $highestRow=$objWorksheet->gethighestrow ();//number of rows obtained - $highestColumn=$objWorksheet-Gethighestcolumn (); - $highestColumnIndex= Phpexcel_cell::columnindexfromstring ($highestColumn);//gets the number of columns - $excelData=Array(); - for($row= 2;$row<=$highestRow;$row++) { in for($col= 0;$col<$highestColumnIndex;$col++) { - $excelData[$row][] =$objWorksheet->getcellbycolumnandrow ($col,$row),GetValue (); to } + } - return $excelData; the}
Phpexcel importing Excel data into a database