当前位置:首页 > PHP教程 > PHP常见问题

php通过PHPExcel导入Excel表格到MySQL数据库的简单实例

如下所示:

<?php define('base_url', realpath(dirname(__file__))); require_once base_url . '/phpexcel/phpexcel.php';//引入phpexcel类文件 //excel文件的地址 $excel_fiel_path = './phpexcel.xls'; $phpexcel = new phpexcel();// 实例化phpexcel工具类 //分析文件获取后缀判断是2007版本还是2003 $extend = pathinfo("./" . $excel_fiel_path); $extend = strtolower($extend["extension"]); // 判断xlsx版本,如果是xlsx的就是2007版本的,否则就是2003 if ($extend=="xlsx") { $phpreader = new phpexcel_reader_excel2007(); $phpexcel = $phpreader->load("./" . $excel_fiel_path); }else{ $phpreader = new phpexcel_reader_excel5(); $phpexcel = $phpreader->load("./" . $excel_fiel_path); } /* 第二种方法*/ $objworksheet = $phpexcel->getactivesheet(); $highestrow = $objworksheet->gethighestrow(); echo 'highestrow='.$highestrow; echo "<br>"; $highestcolumn = $objworksheet->gethighestcolumn(); $highestcolumnindex = phpexcel_cell::columnindexfromstring($highestcolumn);//总列数 echo 'highestcolumnindex='.$highestcolumnindex; echo "<br>"; $headtitle=array(); for ($row = 2;$row <= $highestrow;$row++) { $strs=array(); //注意highestcolumnindex的列数索引从0开始 for ($col = 0;$col < $highestcolumnindex;$col++) { $strs[$col] =$objworksheet->getcellbycolumnandrow($col, $row)->getvalue(); } //todo //连接mysql ,一条条写入 }

以上就是小编为大家带来的php通过phpexcel导入excel表格到mysql数据库的简单实例全部内容了,希望大家多多支持硕编程~



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐