使用phpexcel类实现excel导入mysql数据库功能(实例代码)
下载phpexcel文件,地址:phpexcel.codeplex.com/
代码示例
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); }
相关推荐
bleach00 2020-11-10
林德强之原创 2020-08-13
PlumRain 2020-08-03
bob于 2020-07-26
dataminer 2020-06-25
neverstopforcode 2020-06-18
zxznsjdsj 2020-06-16
langyue 2020-06-13
huangyx 2020-06-11
鲁氏汤包王 2020-06-11
LWLWLiang 2020-05-28
wkwanglei 2020-05-26
Coohx 2020-04-13
thunderstorm 2020-05-09
Andrea0 2020-05-04
数据库工具开发 2020-04-25
tlsmile 2020-04-24
helencoder 2020-04-10