欢迎您光临深圳塔灯网络科技有限公司!
电话图标 余先生:13699882642

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

发表日期:2018-05 文章编辑:小灯 浏览次数:3120

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


本页内容由塔灯网络科技有限公司通过网络收集编辑所得,所有资料仅供用户参考了本站不拥有所有权,如您认为本网页中由涉嫌抄袭的内容,请及时与我们联系,并提供相关证据,工作人员会在5工作日内联系您,一经查实,本站立刻删除侵权内容。本文链接:http://dengtar.com/11263.html
相关cms文章
 八年  行业经验

多一份参考,总有益处

联系深圳网站公司塔灯网络,免费获得网站建设方案及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:余经理:13699882642

Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.