BanzuiExcelExport.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Exports;
  3. use App\Models\User;
  4. use Illuminate\Support\Facades\Log;
  5. use Maatwebsite\Excel\Concerns\FromCollection;
  6. use Maatwebsite\Excel\Concerns\WithEvents;
  7. use Maatwebsite\Excel\Concerns\WithHeadings;
  8. use Maatwebsite\Excel\Concerns\WithTitle;
  9. use Maatwebsite\Excel\Events\AfterSheet;
  10. class BanzuiExcelExport implements FromCollection, WithHeadings, WithEvents
  11. {
  12. protected $data;
  13. public function __construct($data){
  14. $this->data = $data;
  15. }
  16. public function collection()
  17. {
  18. return $this->data;
  19. }
  20. public function headings(): array
  21. {
  22. return['进货月份',
  23. '进货人(批发商)昵称',
  24. '进货人(批发商)手机号',
  25. '半醉浓香型件数',
  26. '半醉酱香型件数',
  27. '件数合计',
  28. '每件补助',
  29. '补助金额',
  30. '补助接收者昵称',
  31. '补助接收者手机号',
  32. '补助接收者身份'
  33. ];
  34. }
  35. public function setRowHeight(array $rouHeight)
  36. {
  37. $this->RowHeight=$rouHeight;
  38. }
  39. public function registerEvents(): array
  40. {
  41. return [
  42. AfterSheet::class => function(AfterSheet $event) {
  43. // 合并单元格,从 A1 到 C1
  44. $sheet = $event->sheet;
  45. // $sheet->mergeCells('A1:C1');
  46. // $sheet->setCellValue('A1','进货人信息');
  47. // 设置字体加粗、居中等样式
  48. // $sheet->getStyle('A1')->getFont()->setBold(true);
  49. // $sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
  50. //
  51. //// $sheet->mergeCells('D1:I1');
  52. //// $sheet->setCellValue('D1','进货数量及金额');
  53. //
  54. // // 设置字体加粗、居中等样式
  55. // $sheet->getStyle('D1')->getFont()->setBold(true);
  56. // $sheet->getStyle('D1')->getAlignment()->setHorizontal('center');
  57. //
  58. //// $sheet->mergeCells('J1:L1');
  59. //// $sheet->setCellValue('J1','拿补助的人信息');
  60. //
  61. //
  62. // // 设置字体加粗、居中等样式
  63. // $sheet->getStyle('J1')->getFont()->setBold(true);
  64. // $sheet->getStyle('J1')->getAlignment()->setHorizontal('center');
  65. //
  66. //// $sheet->mergeCells('M1:N1');
  67. //// $sheet->setCellValue('M1','补助明细及金额');
  68. //
  69. // $sheet->getStyle('M1')->getFont()->setBold(true);
  70. // $sheet->getStyle('M1')->getAlignment()->setHorizontal('center');
  71. //
  72. // $sheet->getColumnDimension('B')->setWidth(20);
  73. // $sheet->getColumnDimension('K')->setWidth(20);
  74. // $sheet->setHeight=20;
  75. // $sheet->getStyle('A:N')->getAlignment()->setHorizontal('center');
  76. $sheet->getColumnDimension('A:K')->setWidth(20);
  77. },
  78. ];
  79. }
  80. }