php execl上传,上传 phpexcel 类 入库后去重

upload.html 页面

upload.php

//set_time_limit(300);设置超时时间

require_once "../upload/PHPExcel_1.8.0_doc/Classes/PHPExcel/IOFactory.php";

$object =new  PHPExcel();

$filePath =$_FILES["file"]["tmp_name"];

$fileType = PHPExcel_IOFactory::identify($filePath); //文件名自动判断文件类型

$objReader = PHPExcel_IOFactory::createReader($fileType);

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

$currentSheet = $objPHPExcel->getSheet(0); //第一个工作簿

$allRow = $currentSheet->getHighestRow(); //行数

/**取得最大的列号*/

$allColumn = $currentSheet->getHighestColumn();

//循环读取每个单元格的内容。注意行从1开始,列从A开始

/*for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){

for($colIndex='A';$colIndex<=$allColumn;$colIndex++){

$addr = $colIndex.$rowIndex;

$cell = $currentSheet->getCell($addr)->getValue();

if($cell instanceof PHPExcel_RichText)     //文本转换字符串

$cell = $cell->__toString();

$sql="insert into tongji (addtime,provice,partner_code,partner,yw_code,yw_name,day_total,

day_dstotal,day_hftotal,day_xzuser,day_xzcs,day_freeuser,day_freecs,day_payuser,day_paycs

,day_loginuser,day_logincs,day_falshuser,day_flashcs,day_ARPU,day_newuser) values $cell" ;

print_r($sql);die;

$list=mysql_query($sql);

print_r($list);die;

}

*/

//$rowIndex=2;这个表示从表格的第二行开始

for($rowIndex=2;$rowIndex<=$allRow+1;$rowIndex++){

if($objPHPExcel->getActiveSheet()->getCell("A".$rowIndex)->getValue()){

if($objPHPExcel->getActiveSheet()->getCell("A".$rowIndex)->getValue()){

$hba=strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("A".$rowIndex)->getValue()));

$hbb=strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("B".$rowIndex)->getValue()));

$new_arr[]=

'(\''.$hba.'\','.

"'".($hbb.'')."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("C".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("D".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("E".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("F".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("G".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("H".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("I".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("J".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("K".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("L".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("M".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("N".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("O".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("P".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("Q".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("R".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("S".$rowIndex)->getValue()))."'".','.

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("T".$rowIndex)->getValue()))."'".','.

//strtotime(date('Y-m-d H:i:s')).",".

"'".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("U".$rowIndex)->getValue()))."'".')';

}

}

}

mysql_connect("localhost","root","root");

$aa=mysql_select_db("count");

mysql_query("set names utf8");

//入库

if(is_array($new_arr)){

$execl=implode(',',$new_arr);

$sql=mysql_query("insert into tongji (addtime,province,partner_code,partner,yw_code,yw_name,day_total,

day_dstotal,day_hftotal,day_xzuser,day_xzcs,day_freeuser,day_freecs,day_payuser,day_paycs

,day_loginuser,day_logincs,day_falshuser,day_flashcs,day_ARPU,day_newuser) values $execl");

$count=mysql_num_rows(mysql_query("select * from tongji"));

$chongfu=$allRow-$count-1;

echo "成功入库".$count."条".","."重复".$chongfu."条";

}else{

echo 2;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值