PHP导出excel php使用phpexcel导出excel文件
-
-
//载入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');
//设置单元格内容
- //这里的数据可以从数据库中读取,然后再做循环处理
- //by bbs.it-home.org
- $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');
-
复制代码
|
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31