花魁直播高品质美女在线视频互动社区 - 花魁直播官方版

 歡迎來到素材無憂網(wǎng),按 + 收藏我們
登錄 注冊 退出 找回密碼

dedecms織夢后臺增加批量上傳和導(dǎo)出報表的功能

時間: 2018-11-30 10:13 閱讀: 作者:素材無憂網(wǎng)

1、導(dǎo)出csv文件
  <?php
             require_once (dirname(__FILE__) . "/../include/common.inc.php");
              $output = fopen('','w') or die("can't open ");
                          header('Content-Type: application/csv');
                          header('Content-Disposition: attachment; filename="認(rèn)證列表.csv"');
                          $arrkeys = array(
                              iconv('utf-8','gb2312','姓名'),
                              iconv('utf-8','gb2312','電話')//文件表頭
                              );
                          fputcsv($output, $arrkeys);
                          //取得符合條件的數(shù)組
                           $sql = "SELECT * FROM dede_test";
                             $dsql->Execute('me',$sql);
                         while($row = $dsql->GetArray('me')){
                                  $name =$row['name'];
                                  $mobile= $row['mobile']; //循環(huán)
   
                                  $arrkeys = array(
                                      iconv('utf-8','gb2312',$name),
                                      iconv('utf-8','gb2312',$mobile)
                                      );
                                  fputcsv($output, $arrkeys);
                              }
   
                      fclose($output) or die("can't close ");
                      exit();
  ?>

2、導(dǎo)入xls文件
查看源碼   打印代碼幫助
  <?php
             require_once (dirname(__FILE__) . "/../include/common.inc.php");
             include_once("excel/reader.php");
                   $tmp = $_FILES['file']['tmp_name'];
                   if (empty ($tmp)) {
                         ShowMsg("請選擇要導(dǎo)入的Excel文件!","test.php");
                           exit;
                   }
   
                   $save_path = "xls/";
                   $file_name = $save_path.date('Ymdhis') . ".xls";
                   if (copy($tmp, $file_name)) {
                           $xls = new Spreadsheet_Excel_Reader();
                           $xls->setOutputEncoding('utf-8');
                           $xls->read($file_name);
                           for ($i=2; $i<=$xls->sheets[0]['numRows']; $i++) {
                                   $name = $xls->sheets[0]['cells'][$i][1];
                                   $mobile = $xls->sheets[0]['cells'][$i][2]
                                   $data_values .= "('$name','$mobile'),";
                           }
                           $data_values = substr($data_values,0,-1);
                           $sql= "INSERT INTO dede_test (name,mobile) VALUES $data_values";
                          $dsql->ExecuteNoneQuery($sql);
                           $lastInsertID = $dsql->GetLastID();
                       if($dsql){
                              ShowMsg("成功導(dǎo)入!","test.php");
                       }else{
                              ShowMsg("導(dǎo)入失??!","test.php");
                       }
                   }
                 exit();
  ?>

dede后臺導(dǎo)出demo,點(diǎn)擊下載 PHP導(dǎo)出xls

版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!

轉(zhuǎn)載請注明: dedecms織夢后臺增加批量上傳和導(dǎo)出報表的功能

標(biāo)簽:  
相關(guān)文章
模板推薦