php把mysql导出excel_php、mysql导出excel数据

//搜索

$start_time = strtotime($start_date);

$end_time = strtotime($end_date);

$sql = "select a.*,b.order_amount,b.money_paid from ".$ecs->table('invoice')." as a ".

" left join ".$ecs->table('order_info')." as b on a.order_id=b.order_sn".

" where a.add_time >=".$start_time." and a.add_time <=".$end_time." ";

$temp_list = $db->getAll($sql);

if($temp_list){//有数据

$Html='

'.chr(13).chr(10);

$Html.='

时间:'.$start_date.'~'.$end_date.'
编号发票类型发票抬头发票内容订单号金额添加日期收件人联系方式地址

//取得符合条件的数组

for($i=0;$i

$temp_i = $i+1;

if($temp_list[$i][order_amount]==0){

$temp_money = $temp_list[$i][money_paid];

}else{

$temp_money = $temp_list[$i][order_amount];

}

$temp_time = date('Y-m-d', $temp_list[$i]['add_time']);

$Html.='

'.$temp_i.''.$temp_list[$i][type_name].''.$temp_list[$i][top].''.$temp_list[$i][content].''.$temp_list[$i][order_id].''.$temp_money.''.$temp_time.''.$temp_list[$i][user_name].''.$temp_list[$i][mobile].' '.$temp_list[$i][tel].' '.$temp_list[$i][address].'';

}

$Html.='

';

$Html.='';

$mime_type = 'application/vnd.ms-excel';

header('Content-Type: ' . $mime_type);

header('Content-Disposition: attachment; filename="invoice.xls"');

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Pragma: public');

echo $Html;

有时excel会自动把数字转换格式,于是有些手机号码,身份证之类的就乱了,因此可以在导出时,先定义好

'.$temp_list[$i][order_id].'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值