dedecms织梦后台增加批量上传和导出报表的功能
互联网
我从窗户里探头往外看,嘿!春天果然到来了。看,外面嫩绿的小草像动画片里的那样,慢慢探出头来。再看,那平坦的草地里,星星点点的眨着眼睛的是什么?哦!那是可爱的小花,还有小虫在花瓣里钻来钻去呢?嘻,原来是童话故事里睡在花瓣里的拇指姑娘啊!再看看,那干枯已久的柳树也伸出了嫩绿的手,轻轻地走来了美丽的春姑娘!
1、导出csv文件
|
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"' ); |
|
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' )){ |
|
$mobile= $row[ 'mobile' ]; //循环 |
|
iconv( 'utf-8' , 'gb2312' ,$name), |
|
iconv( 'utf-8' , 'gb2312' ,$mobile) |
|
fputcsv($output, $arrkeys); |
|
fclose($output) or die( "can't close " ); |
|
2、导入xls文件
|
require_once ( dirname (__FILE__) . "/../include/common.inc.php" ); |
|
include_once( "excel/reader.php" ); |
|
$tmp = $_FILES[ 'file' ][ 'tmp_name' ]; |
|
ShowMsg( "请选择要导入的Excel文件!" , "test.php" ); |
|
$file_name = $save_path. date ( 'Ymdhis' ) . ".xls" ; |
|
if (copy($tmp, $file_name)) { |
|
$xls = new Spreadsheet_Excel_Reader(); |
|
$xls->setOutputEncoding( 'utf-8' ); |
|
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(); |
|
ShowMsg( "成功导入!" , "test.php" ); |
|
ShowMsg( "导入失败!" , "test.php" ); |
|
dede后台导出demo,点击下载PHP导出xls 以上就是dedecms织梦后台增加批量上传和导出报表的功能。如果当初我们能坚持的走下去,今天的结局就不会这么匆匆收场。更多关于dedecms织梦后台增加批量上传和导出报表的功能请关注haodaima.com其它相关文章!