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

1、导出csv文件

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文件

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

你可能感兴趣的:(php,dedecms)