富贵资源网 Design By www.hznty.com

如下所示:

<"./" . $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数据库的简单实例全部内容了,希望大家多多支持~

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com