• 全国400电话网上服务平台
    强大号码库资源任选,方便,快捷,快速开通。
    咨询热线:400-1100-266  

    dedecms后台增加批量上传和导出报表的功能
    POST TIME:2021-05-24 03:10
    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

    
    关于我们 | 付款方式 | 建站知识 | 增值服务 | 网站模板
    Copyright © 2003-2016
    时间:9:00-21:00 (节假日不休)
    版权所有:巨人网络(扬州)科技有限公司
    总部地址:江苏省信息产业基地11号楼四层
    《增值电信业务经营许可证》 苏B2-20120278
    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信

    微信号已复制,请打开微信添加咨询详情!