Download Phpexcel file, address: phpexcel.codeplex.com/
code example
Require_once ' phpexcel/classes/phpexcel.php '; require_once ' phpexcel/classes/phpexcel/iofactory.php '; require_once ' phpexcel/classes/phpexcel/reader/excel5.php '; $objReader = Phpexcel_iofactory::createreader (' Excel5 ');//use excel2007 for format $objPHPExcel = $objReader->load ($filename); $filename can be an uploaded file, or the specified file $sheet = $objPHPExcel->getsheet (0); $highestRow = $sheet->gethighestrow (); Total number of rows obtained $highestColumn = $sheet->gethighestcolumn (); Total number of columns obtained $k = 0; Iterate through the Excel file, read a line, insert a for ($j =2; $j <= $highestRow; $j + +) {$a = $objPHPExcel->getactivesheet ()->getcell ("a". $J)->getvalue ();//Gets the value of column A $b = $objPHPExcel->getactivesheet ()->getcell ("B". $j)->getvalue ();//Gets the value of column B sql = "INSERT into table VALUES (". $a. ",". $b. ")"; mysql_query ($sql);}
The above this article uses the Phpexcel class to implement the Excel import MySQL database function (instance code) is the small part to share to everybody's entire content, hoped can give everybody a reference, also hoped that everybody supports this station.
The above describes the use of the Phpexcel class to implement Excel import MySQL database function instance code, including the content of MySQL database, I hope to be interested in PHP tutorial friends helpful.