PHP 내보내기 Excel PHP는 phpexcel을 사용하여 Excel 파일을 내보냅니다.
풀어 주다: 2016-07-25 08:54:43
-
-
//载入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