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

发布时间:2019-11-08 发布网站:脚本之家
脚本之家收集整理的这篇文章主要介绍了dedecms织梦后台增加批量上传和导出报表的功能脚本之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1、导出csv文件
 
             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','电话')//文件表头
                              );
                          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',$name),
                                      iconv('utf-8',$mobile)
                                      );
                                  fputcsv($output,$arrkeys);
                              }
   
                      fclose($output) or die("can't close ");
                      exit();
  ?>

2、导入xls文件
查看源码
 
打印代码帮助
 
             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,-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

总结

以上是脚本之家为你收集整理的dedecms织梦后台增加批量上传和导出报表的功能全部内容,希望文章能够帮你解决dedecms织梦后台增加批量上传和导出报表的功能所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:76874919,请注明来意。

脚本之家官方公众号

微信公众号搜索 “ 程序精选 ” ,选择关注!

微信公众号搜索 “ 程序精选 ” ,选择关注!
精选程序员所需精品干货内容!

标签: