久久精品无码av|精品人妻春药中文字幕|成人精品亚洲欧洲国产|国产日韩欧美精品一区二区|污污国产精品免费观看入口|A级毛片无码久久精品免费|久久精品国产亚洲高清剧情介绍|欧美日韩激情视频一区二区三区

首頁(yè)

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

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

在php編程語(yǔ)言中,對(duì)于如何在Excel表格中導(dǎo)入數(shù)據(jù)庫(kù)的方法是很多編程者比較頭疼的一個(gè)問(wèn)題,有些技術(shù)人員可能在百度嘗試過(guò)搜索很多不同的問(wèn)題,但是給出的答案經(jīng)過(guò)自己測(cè)試之后,發(fā)現(xiàn)還是行不通,那么對(duì)此,專業(yè)的app開(kāi)發(fā)報(bào)價(jià)燚軒科技也嘗試了一下如何在Excel表格中導(dǎo)入數(shù)據(jù)庫(kù),現(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('上傳失敗,上傳的表格不能超過(guò)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表示從哪一行開(kāi)始讀取  從第二行開(kāi)始讀取,因?yàn)榈谝恍惺菢?biāo)題不保存

            //$a表示列號(hào)

        $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ī)號(hào))列的值

             $arr['name']=$name;

             $arr['tel']=$tel;

              

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

             $arr['geti']=0;

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

              

                

            }

            if($res){

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

            }else{

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

            }

        }

}

 

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

  //通過(guò)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ù)庫(kù)的具體方法了,希望有不懂的技術(shù)人員可以在評(píng)論中提出,我們會(huì)為您解答。

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

熱貼More +

服務(wù)范圍More +

聯(lián)系我們

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

854221200@qq.com

185-3825-9583

QQ客服

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

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

百度提供搜索支持

馆陶县| 双江| 衡阳市| 晋城| 江油市| 绥化市| 宣汉县| 贵港市| 米易县| 分宜县| 元谋县| 屯昌县| 井冈山市| 丰城市| 陕西省| 齐齐哈尔市| 岳普湖县| 沁阳市| 贞丰县| 土默特左旗| 甘南县| 慈利县| 辽阳市| 湘潭市| 墨竹工卡县| 赞皇县| 兰州市| 泽库县| 安康市| 汶上县| 鄂尔多斯市| 泉州市| 井冈山市| 灵山县| 常山县| 长兴县| 平顺县| 凌云县| 若尔盖县| 阜平县| 内黄县|