Download the 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 2007 format $objPHPExcel = $objReader->load($filename); //$filename可以是上传的文件,或者是指定的文件 $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumn = $sheet->getHighestColumn(); // 取得总列数 $k = 0; //循环读取excel文件,读取一条,插入一条 for($j=2;$j<=$highestRow;$j++) { $a = $objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();//获取A列的值 $b = $objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();//获取B列的值 $sql = "INSERT INTO table VALUES(".$a.",".$b.")"; mysql_query($sql); }
The above article uses the phpexcel class to implement the excel import mysql database function (example code) is all the content that the editor has shared with you , I hope it can give you a reference, and I also hope you will support this site.
The above introduces the example code of using the phpexcel class to realize the function of Excel importing mysql database, including the content of Mysql database. I hope it will be helpful to friends who are interested in PHP tutorials.