本文章来给大家介绍一款phpexcel读取excel并导入数据库代码实现,有需要了解的朋友可参考,这里我们介绍的是读取表格之后再创建mysql连接,然后保存到mysql数据库。
phpexcel是相当强大的 ms office excel 文档生成类库,当需要输出比较复杂格式数据的时候,phpexcel 是个不错的选择。不过其使用方法相对来说也就有些繁琐
代码如下 复制代码
query('set names utf8;');
}catch(pdoexception $e){
echo 连接失败.$e->getmessage();
}
//pdo绑定参数操作
$stmt = $dbh->prepare(insert into alumni(gid,student_no,name) values (:gid,:student_no,:name) );
$stmt->bindparam(:gid, $gid,pdo::param_str);
$stmt->bindparam(:student_no, $student_no,pdo::param_str);
$stmt->bindparam(:name, $name,pdo::param_str);
$objreader = new phpexcel_reader_excel5(); //use excel2007
$objphpexcel = $objreader->load('bks.xls'); //指定的文件
$sheet = $objphpexcel->getsheet(0);
$highestrow = $sheet->gethighestrow(); // 取得总行数
$highestcolumn = $sheet->gethighestcolumn(); // 取得总列数
for($j=1;$j {
$student_no = $objphpexcel->getactivesheet()->getcell(a.$j)->getvalue();//第一列学号
$name = $objphpexcel->getactivesheet()->getcell(b.$j)->getvalue();//第二列姓名
$gid = $objphpexcel->getactivesheet()->getcell(c.$j)->getvalue();//第三列gid
}
//将获取的excel内容插入到数据库
$stmt->execute();
?>
http://www.bkjia.com/phpjc/630718.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/630718.htmltecharticle本文章来给大家介绍一款phpexcel读取excel并导入数据库代码实现,有需要了解的朋友可参考,这里我们介绍的是读取表格之后再创建mysql连接...