猎凡网络承接仿站、网站定制业务,诚邀您的合作! 猎凡网为你提供:dedecms织梦仿站帝国cms仿站网站定制、企业仿站等服务,欢迎您的访问!
<
>
当前位置: 首页 > 仿站知识

dedecms织梦后台增加批量上传和导出报表的功能

时间:2019-09-08 15:00:01  来源:admin  作者:猎凡网络

1、导出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="认证列表.csv"');                         $arrkeys = array(                             iconv('utf-8','gb2312','姓名'),                             iconv('utf-8','gb2312','电话')//文件表头                             );                         fputcsv($output, $arrkeys);                         //取得符合条件的数组                          $sql = "SELECT * FROM dede_test";                            $dsql->Execute('me',$sql);                        while($row = $dsql->GetArray('me')){                                 $name =$row['name'];                                 $mobile= $row['mobile']; //循环                                   $arrkeys = array(                                     iconv('utf-8','gb2312',$name),                                     iconv('utf-8','gb2312',$mobile)                                     );                                 fputcsv($output, $arrkeys);                             }                       fclose($output) or die("can't close ");                     exit(); ?>

2、导入xls文件

查看源码

 

打印代码帮助

 <?php            require_once (dirname(__FILE__) . "/../include/common.inc.php");            include_once("excel/reader.php");                  $tmp = $_FILES['file']['tmp_name'];                  if (empty ($tmp)) {                        ShowMsg("请选择要导入的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("成功导入!","test.php");                      }else{                             ShowMsg("导入失败!","test.php");                      }                  }                exit(); ?>

dede后台导出demo,点击下载 PHP导出xls

<

本文网址:https://fangzhan.seobr.com/news/115.html
本文由猎凡仿站网发布,如果您还想了解更多关于网站仿制的文章,请点击查看 仿站知识 的其它文章,转发请注明来源及版权归属。
承接以下业务:传统网站改自适应网站、网站增加手机站、网站改全屏网站改大屏展示、GBK转UFT-8、DEDECMS转WORDPRESS、网站站群制作、企业网站设计、企业网站优化、网站托管等业务

标签:文件   表头
相关文章

数年专注于仿站建站,擅长dedecms仿站、WORDPRESS仿站、帝国cms仿站、网站改版等业务! Copyright©2019 猎凡仿站网 All Rights Reserved