common.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. use think\Db;
  3. /**
  4. * 导出excel文件
  5. */
  6. function phpExcelListNew($field=[],$list=[],$title='文件'){
  7. $PHPExcel=new \PHPExcel();
  8. $PHPSheet=$PHPExcel->getActiveSheet();
  9. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  10. foreach($list as $key=>$value)
  11. {
  12. foreach($field as $k=>$v){
  13. if($key == 0){
  14. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  15. }
  16. $i=$key+2;
  17. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  18. }
  19. }
  20. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  21. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  22. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  23. header('Cache-Control: max-age=0'); //禁止缓存
  24. $PHPWriter->save("php://output"); //输出到浏览器
  25. }
  26. /**
  27. * 导出excel文件
  28. */
  29. function sendExcel($title='文件',$field=[],$list=[]){
  30. $PHPExcel=new \PHPExcel();
  31. $PHPSheet=$PHPExcel->getActiveSheet();
  32. $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
  33. foreach($list as $key=>$value)
  34. {
  35. foreach($field as $k=>$v){
  36. if($key == 0){
  37. $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
  38. }
  39. $i=$key+2;
  40. $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
  41. }
  42. }
  43. $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
  44. header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
  45. header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
  46. header('Cache-Control: max-age=0'); //禁止缓存
  47. $PHPWriter->save('excel_log/'.$title.".xls"); //输出到浏览器
  48. }
  49. function get_area($id){
  50. $add = Db::name('q_area')->where('id', $id)->value('name');
  51. return $add;
  52. }