php数据几行代码导出到excel(非插件)

<?php

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=打钱记录.xls");   
header("Content-Transfer-Encoding:binary"); 
echo iconv("UTF-8", "GBK", "申请时间"); echo "\t";
echo iconv("UTF-8", "GBK", "支付时间") ;echo "\t";  

foreach($list as $key => $val) { 
    echo "\r\n";
    echo iconv("UTF-8", "GBK", "".date("Y-m-d H:i:s", $val['add_time'])); echo "\t";
    echo iconv("UTF-8", "GBK", "".date("Y-m-d H:i:s", $val['pay_time'])); echo "\t";
}

需要注意一个坑, 当输入的数字过长的时候excel会自动截取变掉这个数据,输出的时候要把过长的数据加双引号变成字符串才可以避免这个问题

posted @ 2017-09-30 17:37  一颗星—Broken  阅读(385)  评论(0编辑  收藏  举报