首页 >后端开发 >php教程 >php_excel / output.php

php_excel / output.php

WBOY
WBOY原创
2016-06-23 13:28:241175浏览

<?php$data = array(	array('name'=>'Tom','age'=>61,'date'=>'2014-09-24 12:00:00'),	array('name'=>'Mark','age'=>25,'date'=>'2014-09-23 11:00:00'),	array('name'=>'Lucy','age'=>43,'date'=>'2014-09-22 10:00:00'),);$title = array(	'姓名',	'age',	'时间',);exportexcel($data,$title);die();/** * 导出excel * @param array $data 数据集 * @param array $title 标题集 * @param string $filename 导出的excel文件名 */function exportexcel($data=array(),$title=array(),$filename='report'){	header("Content-type:application/vnd.ms-excel");	header("Content-Disposition:filename=".$filename.".xls");	//导出xls 开始	if (!empty($title))	{		foreach ($title as $k => $v)		{			$title[$k] = iconv("UTF-8", "GBK",$v);		}		$title = implode("\t", $title);		echo "$title\n";	}	if (!empty($data))	{		foreach($data as $key=>$val)		{			foreach ($val as $ck => $cv)			{				$data[$key][$ck] = iconv("UTF-8", "GBK", $cv);			}			$data[$key] = implode("\t", $data[$key]);		}		echo implode("\n",$data);	}}


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn