excel导出
Posted 迷失在路上
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了excel导出相关的知识,希望对你有一定的参考价值。
public function download()
{
$strTable =\'<table width="500" border="1">\';
$strTable .= \'<tr>\';
$strTable .= \'<td style="text-align:center;font-size:12px;width:120px;">会员ID</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="100">会员昵称</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">会员等级</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">手机号</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">邮箱</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">注册时间</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">最后登陆</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">余额</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">积分</td>\';
$strTable .= \'<td style="text-align:center;font-size:12px;" width="*">累计消费</td>\';
$strTable .= \'</tr>\';
$count = M(\'auth_rule\')->count();
$p = ceil($count/5000);
for($i=0;$i<$p;$i++){
$start = $i*5000;
$end = ($i+1)*5000;
$userList = M(\'auth_rule\')->order(\'id\')->limit($start.\',\'.$end)->select();
if(is_array($userList)){
foreach($userList as $k=>$val){
$strTable .= \'<tr>\';
$strTable .= \'<td style="text-align:center;font-size:12px;">\'.$val[\'id\'].\'</td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.$val[\'name\'].\' </td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.$val[\'title\'].\'</td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.$val[\'type\'].\'</td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.$val[\'status\'].\'</td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.date(\'Y-m-d H:i\',$val[\'condition\']).\'</td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.date(\'Y-m-d H:i\',$val[\'pid\']).\'</td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.$val[\'level\'].\'</td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.\'2212\'.\' </td>\';
$strTable .= \'<td style="text-align:left;font-size:12px;">\'.\'5555\'.\' </td>\';
$strTable .= \'</tr>\';
}
unset($userList);
}
}
$strTable .=\'</table>\';
$filename = \'users_\';
header("Content-type: application/vnd.ms-excel");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$filename."_".date(\'Y-m-d\').".xls");
header(\'Expires:0\');
header(\'Pragma:public\');
echo \'<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\'.$strTable.\'</html>\';
}
以上是关于excel导出的主要内容,如果未能解决你的问题,请参考以下文章