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
免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。