//错误处理 时区设置
error_reporting(E_ALL);
ini_set('display_errors',TRUE);
ini_set('display_startup_errors',TRUE);
date_default_timezone_set('PRC');
require_once './Classes/PHPExcel.php';
$obj = new PHPExcel();
//设置文档属性
$obj->getProperties()->setCreator('IIIThSoul')//创建者
->setLastModifiedBy('IIIThSoul')//最后修改者
->setTitle('PHPExcel Test Document')//标题
->setSubject('PHPExcel Test Document')//主题
->setDescription('PHPExcel测试文档')//设置文档描述
->setKeyWords('office PHPExcel php')//关键词
->setCategory('Test result file');//分类
//添加一些数据
$obj->setActiveSheetIndex(0)//设置活动表格
->setCellValue('A1','Hello')//在表格位置加值
->setCellValue('B2','World!')
->setCellValue('C1','Hello ')
->setCellValue('D2','World');
$obj->getActiveSheet()->setCellValue('A8',"Hello\nWorld!");
$obj->getActiveSheet()->getRowDimension(8)->setRowHeight(-1);//获取单元格设置高度
$obj->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);//获取单元格样式并设置
//重命名表格
$obj->getActiveSheet()->setTitle('Simple');
//设置活动的表格为第一个,这样就打开了第一个表格
$obj->setActiveSheetIndex(0);
//输出到浏览器(Excel)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
//如果浏览器为IE9 那就需要下面的
header('Cache-Control:max-age=1');
/*
//如果服务通过SSL,则需要下面的
header('Expires:Mon,26 Jul 1997 05:00:00 GMT');
header('Last-Modified:'.gmdate('D,d M Y H:i:s').' GMT');//宗师在被修改
header('Cache-Control:cache,must-revalidate');
header('Pragma:public');//HTTP/1.0
*/
$obj = PHPExcel_IOFactory::createWriter($obj,'Excel5');
$obj->save('php://output');