//载入PHPExcel类
require './phpexcel/PHPExcel.php';
//创建一个excel对象实例
$objPHPExcel = new PHPExcel();
//设置文档基本属性
$objProps = $objPHPExcel->getProperties();
$objProps->setCreator("Lao Mao");
$objProps->setLastModifiedBy("Lao Mao");
$objProps->setTitle("Office XLS Test Document");
$objProps->setSubject("Office XLS Test Document, Demo");
$objProps->setDescription("Test document, generated by PHPExcel.");
$objProps->setKeywords("office excel PHPExcel");
$objProps->setCategory("Test");
//设置当前的sheet索引,用于后续的内容操作。
//一般只有在使用多个sheet的时候才需要显示调用。
//缺省情况下,PHPExcel会自动创建第一个sheet被设置SheetIndex=0
$objPHPExcel->setActiveSheetIndex(0);
//设置当前活动sheet的名称
$objActSheet = $objPHPExcel->getActiveSheet();
$objActSheet->setTitle('测试Sheet');
//设置单元格内容www.111cn.net
//这里的数据可以从数据库中读取,然后再做循环处理
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'a1');
$objPHPExcel->getActiveSheet()->SetCellValue('A2', 'a2');
$objPHPExcel->getActiveSheet()->SetCellValue('A3', 'a3');
$objPHPExcel->getActiveSheet()->SetCellValue('A4', 'a4');
$objPHPExcel->getActiveSheet()->SetCellValue('A5', 'a5');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'b1');
$objPHPExcel->getActiveSheet()->SetCellValue('B2', 'b2');
$objPHPExcel->getActiveSheet()->SetCellValue('B3', 'b3');
$objPHPExcel->getActiveSheet()->SetCellValue('B4', 'b4');
$objPHPExcel->getActiveSheet()->SetCellValue('B5', 'b5');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'c1');
$objPHPExcel->getActiveSheet()->SetCellValue('C2', 'c2');
$objPHPExcel->getActiveSheet()->SetCellValue('C3', 'c3');
$objPHPExcel->getActiveSheet()->SetCellValue('C4', 'c4');
$objPHPExcel->getActiveSheet()->SetCellValue('C5', 'c5');
//输出文档
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
//设置header头部信息,并输出到浏览器
//header('Content-Type: application/vnd.ms-excel');
//header("Content-Disposition:attachment; filename=demo.xls");
//header('Cache-Control: max-age=0');
//$objWriter->save('php://output');
//保存至某一位置
$objWriter->save(dirname(__FILE__) . '/demo.xls');
|