亚洲精品专区av无码专区,久久久久人妻精品一区三寸,亚洲AⅤ无码一区二区波多野按摩,国产浪潮AV无码喷水

首頁

Excel表格導(dǎo)入數(shù)據(jù)庫的方法詳解

PHPExcel表格數(shù)據(jù)庫 2018-05-02 6095

在php編程語言中,對于如何在Excel表格中導(dǎo)入數(shù)據(jù)庫的方法是很多編程者比較頭疼的一個(gè)問題,有些技術(shù)人員可能在百度嘗試過搜索很多不同的問題,但是給出的答案經(jīng)過自己測試之后,發(fā)現(xiàn)還是行不通,那么對此,專業(yè)的app開發(fā)報(bào)價(jià)燚軒科技也嘗試了一下如何在Excel表格中導(dǎo)入數(shù)據(jù)庫,現(xiàn)在將源代碼展示給各位技術(shù)編程者,大家可以借鑒參考一下。

public function saveexcel(){

       require_once('./Thinkphp/Extend/Vendor/PHPExcel-1.8/Classes/PHPExcel.php');

       require_once('./Thinkphp/Extend/Vendor/PHPExcel-1.8/Classes/PHPExcel/IOFactory.php');

       require_once('./Thinkphp/Extend/Vendor/PHPExcel-1.8/Classes/PHPExcel/Reader/Excel5.php');

        //獲取表格的大小,限制上傳表格的大小5M

        // $file_size = $_FILES['myfile']['size'];

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

        // echo "<script>alert('上傳失敗,上傳的表格不能超過5M的大小');history.go(-1);</script>";

        //     exit();

        // }

 

        //限制上傳表格類型

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

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

        echo "<script>alert('上傳失敗,只能上傳excel200397-2003xls格式!');history.go(-1)</script>";

        exit();

        }

 

        //判斷表格是否上傳成功

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

            

            //以上三步加載phpExcel的類

 

        $objReader = \PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format

            //接收存在緩存中的excel表格

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

        $objPHPExcel = $objReader->load($filename); //$filename可以是上傳的表格,或者是指定的表格

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

        $highestRow = $sheet->getHighestRow(); // 取得總行數(shù)

     // $highestColumn = $sheet->getHighestColumn(); // 取得總列數(shù)

            

            //循環(huán)讀取excel表格,讀取一條,插入一條

            //j表示從哪一行開始讀取  從第二行開始讀取,因?yàn)榈谝恍惺菢?biāo)題不保存

            //$a表示列號

        $model=M('user');

        $rechargemodel=M('recharge');

        $joinmodel=M('joinplan');

 

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

        {

            $name = $objPHPExcel->getActiveSheet()->getCell("B".$j)->getValue();//獲取B(姓名)列的值

            $tel = $objPHPExcel->getActiveSheet()->getCell("C".$j)->getValue();//獲取C(手機(jī)號)列的值

             $arr['name']=$name;

             $arr['tel']=$tel;

              

             $arr['addtime']=time();

             $arr['geti']=0;

             $res=$model->add($arr);

              

                

            }

            if($res){

                success('添加成功',U('userlist'));

            }else{

                error('操作失敗,請稍后再試');

            }

        }

}

 

Php excel 文件

 

代碼導(dǎo)出(不需要引入 任何接口)

     public function  exportDayInner(){

          $model = M("Goodsinfo");

          // $innerdata = $mod->select();

          $list = $model->order('gid desc')->select();


                      // echo $mod->getLastSql();exit;

                      // dump($innerdata);die;

          $table = '';

          $table .= "<table align='center' border='1' cellpadding'0' cellspacing='0'>

                      <thead>

                      <tr>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      <th class='name'>名稱</th>

                      </tr>

                      </thead>

                      <tbody>";

                      foreach ($list as $v) {

                      $table .= "<tr align='center'>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$a[$v['gname']]}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$b[$v['gname']]}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}/{$v['gname']} </td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}%</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$v['gname']}</td>

                      <td class='name'>{$c[$v['gname']]}</td>                

                      </tr>";

                      }

                      $table .= "</tbody>

                      </table>";

  //通過header頭控制輸出excel表格

                      header("Pragma: public");  

                      header("Expires: 0");  

                      header("Cache-Control:must-revalidate, post-check=0, pre-check=0");  

                      header("Content-Type:application/force-download");  

                      header("Content-Type:application/vnd.ms-execl");  

                      header("Content-Type:application/octet-stream");  

                      header("Content-Type:application/download");

                      header('Content-Disposition:attachment;filename="商品列表.xls"');  

                      header("Content-Transfer-Encoding:binary");  

                      echo $table;

      }

以上就是為各位講解的如何在Excel表格中導(dǎo)入數(shù)據(jù)庫的具體方法了,希望有不懂的技術(shù)人員可以在評論中提出,我們會為您解答。

分享到微信朋友圈 +
打開微信,點(diǎn)擊底部的“發(fā)現(xiàn)”,使用 “掃一掃” 即可將網(wǎng)頁分享到我的朋友圈。 如何使用?
推薦文章

熱貼More +

服務(wù)范圍More +

聯(lián)系我們

請掃二維碼聯(lián)系客服

854221200@qq.com

185-3825-9583

QQ客服

關(guān)于  ·  招聘  ·  案例中心  ·  網(wǎng)站地圖

?@2018 燚軒科技版權(quán)所有 豫ICP備16015002號-4

百度提供搜索支持

弋阳县| 昭通市| 沛县| 武陟县| 太康县| 清流县| 静海县| 融水| 堆龙德庆县| 南江县| 茌平县| 黑河市| 丹凤县| 潮安县| 五大连池市| 循化| 克山县| 噶尔县| 长泰县| 沙田区| 沾益县| 河南省| 乳源| 会同县| 宁河县| 怀化市| 迁安市| 祁东县| 家居| 宜黄县| 子长县| 锡林浩特市| 涪陵区| 台北县| 调兵山市| 临武县| 都匀市| 东辽县| 安阳市| 阳朔县| 兴仁县|