/*
* phpexcel导出excel文件
* edit:
*/
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
//设置属性
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office XLSX Test Document")
->setSubject("Office XLSX Test Document")
->setDescription("Test document for Office XLSX, generated using PHP classes.")
->setKeywords("office openxml php")
->setCategory("Test result file");
// 添加一些数据
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', iconv('gbk', 'utf-8', '中文Hello'))
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', '11111');
// 修改sheet名称
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>