upload.html 页面 <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" id="file" name="file" > <input type="button" onclick="file.click()" value="选择附件"> <input type="submit" value="提交" /> </form> upload.php <?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; }
时间: 2024-10-10 04:08:42