织梦dedecms后台增加批量上传和导出报表功能,支持csv文件、xls文件导入导出。有了这个功能方便内容的整理。
1、织梦dedecms后台导出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、织梦dedecms后台导入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(); ?>
需要织梦excel表批量导入请移步《织梦dedecms批量导入excel表文章内容插件》
织梦二次开发QQ群
本站客服QQ号:862782808(点击左边QQ号交流),群号(383578617) 如果您有任何织梦问题,请把问题发到群里,阁主将为您写解决教程!
转载请注明: 织梦模板 » 织梦后台增加批量上传和导出报表功能,支持csv及xls文件