ExcelExport.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 ExcelExport implements FromCollection, WithHeadings, WithEvents
  11. {
  12. public function collection()
  13. {
  14. return collect(
  15. [
  16. '2024年9月',
  17. '艳霞',
  18. '156****9339',
  19. '38',
  20. '',
  21. '38',
  22. '20',
  23. '760',
  24. '小温',
  25. '133****3328',
  26. '批发商',
  27. ]
  28. );
  29. }
  30. public function headings(): array
  31. {
  32. return['进货月份',
  33. '进货人(批发商)昵称',
  34. '进货人(批发商)手机号',
  35. '半醉浓香型件数',
  36. '半醉酱香型件数',
  37. '件数合计',
  38. '每件补助',
  39. '补助金额',
  40. '补助接收者昵称',
  41. '补助接收者手机号',
  42. '补助接收者身份'
  43. ];
  44. }
  45. public function setRowHeight(array $rouHeight)
  46. {
  47. $this->RowHeight=$rouHeight;
  48. }
  49. public function registerEvents(): array
  50. {
  51. return [
  52. AfterSheet::class => function(AfterSheet $event) {
  53. // 合并单元格,从 A1 到 C1
  54. $sheet = $event->sheet;
  55. // $sheet->mergeCells('A1:C1');
  56. // $sheet->setCellValue('A1','进货人信息');
  57. // 设置字体加粗、居中等样式
  58. $sheet->getStyle('A1')->getFont()->setBold(true);
  59. $sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
  60. // $sheet->mergeCells('D1:I1');
  61. // $sheet->setCellValue('D1','进货数量及金额');
  62. // 设置字体加粗、居中等样式
  63. $sheet->getStyle('D1')->getFont()->setBold(true);
  64. $sheet->getStyle('D1')->getAlignment()->setHorizontal('center');
  65. // $sheet->mergeCells('J1:L1');
  66. // $sheet->setCellValue('J1','拿补助的人信息');
  67. // 设置字体加粗、居中等样式
  68. $sheet->getStyle('J1')->getFont()->setBold(true);
  69. $sheet->getStyle('J1')->getAlignment()->setHorizontal('center');
  70. // $sheet->mergeCells('M1:N1');
  71. // $sheet->setCellValue('M1','补助明细及金额');
  72. $sheet->getStyle('M1')->getFont()->setBold(true);
  73. $sheet->getStyle('M1')->getAlignment()->setHorizontal('center');
  74. $sheet->getColumnDimension('B')->setWidth(20);
  75. $sheet->getColumnDimension('K')->setWidth(20);
  76. $sheet->setHeight=20;
  77. // $sheet->getStyle('A:N')->getAlignment()->setHorizontal('center');
  78. },
  79. ];
  80. }
  81. }