php mysql导入表格大量数据,PHP批量导入excell表格到mysql数据库

PHP批量导入excell表格到mysql数据库,本人通过亲自测试,在这里分享给大家

1,下载 php  excell类库

网上搜索可以下载,这里不写地址

2,建html文件

请选择你要上传的EXCELL:excell下载模板
请选择你要上传的excell:

3,php代码写入

//批量上传操作

function upExecel(){

//判断是否选择了要上传的表格

if (empty($_POST[‘myfile‘])) {

echo "";

}

$file_size = $_FILES[‘myfile‘][‘size‘];

if ($file_size>5*1024*1024) {

echo "";

exit();

}

//限制上传表格类型

$file_type = $_FILES[‘myfile‘][‘type‘];

//application/vnd.ms-excel 为xls文件类型

//if ($file_type!=‘application/vnd.ms-excel‘) {

//echo "";

//exit();

//}

if (is_uploaded_file($_FILES[‘myfile‘][‘tmp_name‘])) {

if ($file_type=="application/vnd.ms-excel")

{

$objReader = PHPExcel_IOFactory::createReader(‘Excel5‘);

}

else

{

$objReader = PHPExcel_IOFactory::createReader(‘Excel2007‘);

}

$filename = $_FILES[‘myfile‘][‘tmp_name‘];

$objPHPExcel = $objReader->load($filename);

$sheet = $objPHPExcel->getSheet(0);

$highestRow = $sheet->getHighestRow();

for($j=2;$j<=$highestRow;$j++)

{

$a = $objPHPExcel->getActiveSheet()->getCell("A".$j)->getValue();

$b = $objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();

$c = $objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();

$d = $objPHPExcel->getActiveSheet()->getCell("D".$j)->getValue();

$e = $objPHPExcel->getActiveSheet()->getCell("E".$j)->getValue();

$f = $objPHPExcel->getActiveSheet()->getCell("F".$j)->getValue();

$g = $objPHPExcel->getActiveSheet()->getCell("G".$j)->getValue();

$h = $objPHPExcel->getActiveSheet()->getCell("H".$j)->getValue();

//null 为主键id,自增可用null表示自动添加

//$sql = "INSERT INTO house VALUES(null,‘$a‘,‘$b‘,‘$c‘,‘$d‘,‘$e‘,‘$f‘,‘$g‘,‘$h‘)";

$newrow = array(

‘title‘ => $c,

‘pid‘ => $b,

‘huohao‘ => $a,

‘guige‘ => $d,

‘price‘ => $e,

‘huoc‘ => $f,

‘wendu‘ => $g,

‘zbq‘ => $h,

‘content‘ => $content,

‘upfile‘ => ‘/upload/12.jpg‘,

‘add_time‘ => time(),

);

$row=spClass(‘goods_list‘)->create($newrow);

if ($row){

echo "";

}else{

echo "";

exit();

}

}

}

}

需要注意是:xls文件  用 $objReader = PHPExcel_IOFactory::createReader(‘Excel5‘);  xlsx文件  用 $objReader = PHPExcel_IOFactory::createReader(‘Excel2007‘);

PHP批量导入excell表格到mysql数据库

标签:enter   NPU   pad   aci   添加   turn   row   validate   htm

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:https://www.cnblogs.com/96net/p/11517950.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值