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

收 藏

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’,仿站我们通常所说的仿站是利用CMS(内容管理系统)作为网站的后台,而仿制的则是目标站的静态模板。DEDECMS的标签比较简单,是PHP类网站仿站的首选。,’gb2312′,$name),                                     iconv(‘utf-8′,’gb2312’,dede仿站是针对目标网站进行仿制。仿站主要从页面风格和功能上进行仿制。,$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