1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- use think\Db;
- /**
- * 导出excel文件
- */
- function phpExcelListNew($field=[],$list=[],$title='文件'){
- $PHPExcel=new \PHPExcel();
- $PHPSheet=$PHPExcel->getActiveSheet();
- $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
- foreach($list as $key=>$value)
- {
- foreach($field as $k=>$v){
- if($key == 0){
- $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
- }
- $i=$key+2;
- $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
- }
- }
- $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
- header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
- header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
- header('Cache-Control: max-age=0'); //禁止缓存
- $PHPWriter->save("php://output"); //输出到浏览器
- }
- /**
- * 导出excel文件
- */
- function sendExcel($title='文件',$field=[],$list=[]){
- $PHPExcel=new \PHPExcel();
- $PHPSheet=$PHPExcel->getActiveSheet();
- $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
- foreach($list as $key=>$value)
- {
- foreach($field as $k=>$v){
- if($key == 0){
- $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
- }
- $i=$key+2;
- $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
- }
- }
- $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
- header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
- header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
- header('Cache-Control: max-age=0'); //禁止缓存
- $PHPWriter->save('excel_log/'.$title.".xls"); //输出到浏览器
- }
- function get_area($id){
- $add = Db::name('q_area')->where('id', $id)->value('name');
- return $add;
- }
|