php两种导出excel的方法
程序员文章站
2022-04-01 13:40:36
...
所需要的:jquery库,phpexcel插件,页面导出excel效果测试文件explode.php,excel导出功能实现文件exp.php和explode_excel.php,文件相关内容在此文下面:
";?>
explode.php:测试页面内容:访问此页面后单击explode1与explode2能导出两种不同效果的excel,代码如下:
Date | CSAT Score | Grand Total | CSAT | ||||
08/01/11 | 0 | 0 | 0 | 0 | 0 | 0 | 0% |
08/01/11 | 0 | 0 | 0 | 0 | 0 | 0 | 0% |
08/01/11 | 0 | 0 | 0 | 0 | 0 | 0 | 0% |
第一种,用phpexcel插件导出excel,即exp.php文件中的内容:
getProperties()->setCreator("李汉团");$objPHPExcel->getProperties()->setLastModifiedBy("李汉团");$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); // Add some data$objPHPExcel->setActiveSheetIndex(0);$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Date');//合并单元格:$objPHPExcel->getActiveSheet()->mergeCells('B1:F1');$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'CSAT Score');$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Grand Total');$objPHPExcel->getActiveSheet()->SetCellValue('H1', 'CSAT');$objPHPExcel->getActiveSheet()->SetCellValue('A2', '08/01/11');$objPHPExcel->getActiveSheet()->SetCellValue('B2', '0');$objPHPExcel->getActiveSheet()->SetCellValue('C2', '0');$objPHPExcel->getActiveSheet()->SetCellValue('D2', '0');$objPHPExcel->getActiveSheet()->SetCellValue('E2', '0');$objPHPExcel->getActiveSheet()->SetCellValue('F2', '0');$objPHPExcel->getActiveSheet()->SetCellValue('G2', '0');$objPHPExcel->getActiveSheet()->SetCellValue('H2', '0%');$objPHPExcel->getActiveSheet()->SetCellValue('A3', '08/01/11');$objPHPExcel->getActiveSheet()->SetCellValue('B3', '0');$objPHPExcel->getActiveSheet()->SetCellValue('C3', '0');$objPHPExcel->getActiveSheet()->SetCellValue('D3', '0');$objPHPExcel->getActiveSheet()->SetCellValue('E3', '0');$objPHPExcel->getActiveSheet()->SetCellValue('F3', '0');$objPHPExcel->getActiveSheet()->SetCellValue('G3', '0');$objPHPExcel->getActiveSheet()->SetCellValue('H3', '0%');$objPHPExcel->getActiveSheet()->SetCellValue('A4', '08/01/11');$objPHPExcel->getActiveSheet()->SetCellValue('B4', '0');$objPHPExcel->getActiveSheet()->SetCellValue('C4', '0');$objPHPExcel->getActiveSheet()->SetCellValue('D4', '0');$objPHPExcel->getActiveSheet()->SetCellValue('E4', '0');$objPHPExcel->getActiveSheet()->SetCellValue('F4', '0');$objPHPExcel->getActiveSheet()->SetCellValue('G4', '0');$objPHPExcel->getActiveSheet()->SetCellValue('H4', '0%'); // Rename sheet$objPHPExcel->getActiveSheet()->setTitle('Csat'); // Save Excel 2007 file//$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); $objWriter->save(str_replace('.php', '.xls', __FILE__)); header("Pragma: public"); header("Expires: 0"); header("Cache-Control:must-revalidate,post-check=0,pre-check=0"); header("Content-Type:application/force-download"); header("Content-Type:application/vnd.ms-execl"); header("Content-Type:application/octet-stream"); header("Content-Type:application/download"); header("Content-Disposition:attachment;filename=csat.xls"); header("Content-Transfer-Encoding:binary"); $objWriter->save("php://output");?>
第二种,直接用header导出html,指定样式的excel,即explode_excel.php中的内容,如下:
无标题文档
Date | CSAT Score | Grand Total | CSAT | ||||
08/01/11 | 0 | 0 | 测试内容!! | 0 | 0 | 0 | 0% |
08/01/11 | 0 | 0 | 0 | 0 | 0 | 0 | 0% |
08/01/11 | 0 | 0 | 0 | 0 | 0 | 0 | 0% |
上一篇: 微信支付开发H5支付
推荐阅读
-
PHP错误Warning:mysql_query()的解决方法
-
crontab无法执行php的解决方法_PHP
-
php 更新数据库中断的解决方法_php技巧
-
php简单计算页面加载时间的方法
-
php去掉URL网址中带有PHPSESSID的配置方法,urlphpsessid_PHP教程
-
PHP类的静态(static)方法和静态(static)变量
-
php实现压缩多个CSS与JS文件的方法,
-
PHP遍历关联数组的方法介绍_PHP教程
-
ci检测是ajax还是页面post提交数据的方法,ciajax_PHP教程
-
php警告Creating default object from empty value 问题的解决方法_php技巧