上傳 phpexcel 類 入庫後去重

來源:互聯網
上載者:User

標籤:phpexcel類 上傳 入庫後 去重

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;    }


上傳 phpexcel 類 入庫後去重

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.