有一个非常强大的插件PHPExcel,如果我们不常用到的话,可以自己去实现就不用引入这个PHPExcel了。
请看代码示例
/**
* @todo 导出数据到Excel
*/
public function list2Excel() {
ob_end_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=excel导出实例.xls");
header("Content-Transfer-Encoding: binary ");
echo trim(iconv("UTF-8","GBK","文件名\t"))."\t";
echo trim(iconv("UTF-8","GBK","创建时间\t"))."\t";
echo trim(iconv("UTF-8","GBK","申请人\t"))."\t";
echo trim(iconv("UTF-8","GBK","状态\t"))."\t";
$time = date('Y-m-d H:i:s',time());
for($i = 1; $i <= 30;$i++){
echo "\n";
echo trim(iconv("UTF-8","GBK","测试{$i}.png"))."\t";
echo trim(iconv("UTF-8","GBK","{$time}"))."\t";
echo trim(iconv("UTF-8","GBK","张三{$i}"))."\t";
echo trim(iconv("UTF-8","GBK","\t下载成功\t"))."\t";
}
}