王鹏飞seo博客,专注郑州seo,郑州网站优化,百度seo优化,提供免费seo诊断方案。seo外包顾问QQ:931519643,电话15617834052。
Loading
0

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','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

本站文章均来自互联网,如有侵权请及时联系郑州seo。并发送侵权证明至邮箱931519643@qq.com,证实后立即删除。
鞭挞我吧!鞭挞我吧! 鞭挞我吧!鞭挞我吧!

如果你觉得不错,不如打赏一下!

最后编辑于:2019/4/27作者: 王鹏飞SEO

王鹏飞seo,专注郑州SEO网站优化,分享百度SEO优化知识,提供免费seo优化方案。

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

arrow grin ! ? cool roll eek evil razz mrgreen smile oops lol mad twisted wink idea cry shock neutral sad ???

扫一扫,获取免费seo诊断!

扫一扫,获取免费seo诊断!