通过PHPExcel创建Excel文档
1、创建PHPExcel类(相当于打开Excel软件)
$phpexcel=new PHPExcel();
2、创建Excel文档
方法一、使用createWriter创建
初始化phpwriter类对象,第二个参数:excel5代表是2003版本,excel2007表示高版本
$phpwriter=PHPExcel_IOFACTORY::createWriter($phpexcel,'excel5');
方法二、使用PHPExcel_Writer_EXCEL5创建
$phpwriter=new PHPExcel_Writer_EXCEL5($phpexcel);
3、直接成生Excel文件
$phpwriter->save('test.xls');
4、输出Excel表格到浏览器下载
header('Content-Type: application/vnd.ms-excel');//设置文档类型
header('Content-Disposition: attachment;filename="filename.xls"');//设置文件名
header('Cache-Control: max-age=0');
$phpwriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$phpwriter->save('php://output');
其它header 属性设置
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/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="resume.xls"');
header("Content-Transfer-Encoding:binary");
$objWriter->save('php://output');