PHP导出excel文件,第一步先实现PHP模板导出不带数据

$objReader = PHPExcel_IOFactory::createReader(‘Excel5‘);
$objPHPExcel = $objReader-load("../template/eub.xls");
//print_r($objPHPExcel);
//die();

$filename = "eub-".date("YmdHis").".xls";

// Redirect output to a client’s web browser (Excel2007)
header(‘Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset="GB2312"‘);
header(‘Content-Disposition: attachment;filename="‘.$filename.‘"‘);
header(‘Cache-Control: max-age=0‘);
// If you‘re serving to IE 9, then the following may be needed
header(‘Cache-Control: max-age=1‘);

// If you‘re serving to IE over SSL, then the following may be needed
header (‘Expires: Mon, 26 Jul 1997 05:00:00 GMT‘); // Date in the past
header (‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s‘).‘ GMT‘); // always modified
header (‘Cache-Control: cache, must-revalidate‘); // HTTP/1.1
header (‘Pragma: public‘); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel2007‘);
$objWriter-save(‘php://output‘);
exit;
?

在此期间遇到一个问题代码中的 createReader(‘Excel5‘);代码,是关于phpExcel导入不同excel版本的设置,我用的模板文件是(97-2003 工作表)是2003年以前的版本,2003以前的excel读取实例化excel5类,2003以后需要实例化excel2007类,so,改改$objReader实例化的地方:其中createReader(‘Excel2007‘)改为createReader(‘Excel5‘)

PHP导出excel文件,第一步先实现PHP模板导出不带数据

原文地址:http://www.cnblogs.com/xinyu2017/p/7300821.html


最新回复(0)
/jishupdUts1hjS7Z86l8V5bBm_2BwTVCo8Kf_2F8RgX0j95ji4BI_3D4719002
8 简首页