PHP导出excel
来源:互联网 发布:淘宝宝贝详情怎么做 编辑:程序博客网 时间:2024/06/05 23:56
①通过composer下载,命令行中运行如下命令
composer require phpoffice/phpexcel
②定义一个静态方法
public static function exportExcel($tableHeader,$tableContent,$tableFileName) { // require_once '../vendor/phpoffice/phpexcel/Classes/PHPExcel.php'; //通过composer安装的包,可以直接在代码或控制器中实例化 $objPHPExcel = new \PHPExcel(); //生成表格的列名,A~ZZ(最大702列) $arr = range('A','Z'); $temp = $arr; foreach ($temp as $shi) { foreach ($temp as $ge) { $arr[] = $shi . $ge; } } unset($temp); //设置表头 foreach ($tableHeader as $key => $value) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($arr[$key].'1',(string)$value); } //设置表内容 foreach ($tableContent as $key => $value) { $i = 0; foreach ($value as $value1) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($arr[$i].($key+2),(string)$value1); $i++; } } // $objPHPExcel->getActiveSheet()->setTitle(date('YmdHis').'商品表'); // 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="'.$tableFileName.'.xls"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); }
阅读全文
0 0
- php导出excel
- PHP 导出EXCEL报表
- php导出Excel方法
- PHP导出Excel文件
- php导出Excel
- PHP导出Excel
- php导出excel
- PHP导出excel乱码
- PHP导出导入Excel
- php导出excel
- PHP导出EXCEL
- php导出excel乱码
- php导出excel
- php导出excel
- php导出Excel
- php简单导出excel
- PHP导出Excel文件
- PHP导出excel
- 扩展欧几里得 小白算法学习
- Python常见的错误类型及其继承关系
- 小米手机无法调试应用解决Installation failed with message Failed to establish session.
- ASP常用服务器获取各类信息汇总
- swift ARC中的strong、weak、unowned
- PHP导出excel
- 多校第一场I Curse Myself(HDU6041)
- jmeter 集合点
- Centos6安装mysql5.5
- JQuery在光标位置插入内容
- 逆波兰表达式求值
- Ant与Maven在liunx上的安装
- 牛客网---2016---蘑菇街回文串
- java 日期计算