NeikuExcelExport.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 NeikuExcelExport 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. '补助金额'
  36. ];
  37. }
  38. public function setRowHeight(array $rouHeight)
  39. {
  40. $this->RowHeight=$rouHeight;
  41. }
  42. public function registerEvents(): array
  43. {
  44. return [
  45. AfterSheet::class => function(AfterSheet $event) {
  46. // 合并单元格,从 A1 到 C1
  47. $sheet = $event->sheet;
  48. // $sheet->mergeCells('A1:C1');
  49. // $sheet->setCellValue('A1','进货人信息');
  50. // 设置字体加粗、居中等样式
  51. // $sheet->getStyle('A1')->getFont()->setBold(true);
  52. // $sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
  53. //
  54. //// $sheet->mergeCells('D1:I1');
  55. //// $sheet->setCellValue('D1','进货数量及金额');
  56. //
  57. // // 设置字体加粗、居中等样式
  58. // $sheet->getStyle('D1')->getFont()->setBold(true);
  59. // $sheet->getStyle('D1')->getAlignment()->setHorizontal('center');
  60. //
  61. //// $sheet->mergeCells('J1:L1');
  62. //// $sheet->setCellValue('J1','拿补助的人信息');
  63. //
  64. //
  65. // // 设置字体加粗、居中等样式
  66. // $sheet->getStyle('J1')->getFont()->setBold(true);
  67. // $sheet->getStyle('J1')->getAlignment()->setHorizontal('center');
  68. //
  69. //// $sheet->mergeCells('M1:N1');
  70. //// $sheet->setCellValue('M1','补助明细及金额');
  71. //
  72. // $sheet->getStyle('M1')->getFont()->setBold(true);
  73. // $sheet->getStyle('M1')->getAlignment()->setHorizontal('center');
  74. //
  75. // $sheet->getColumnDimension('B')->setWidth(20);
  76. // $sheet->getColumnDimension('K')->setWidth(20);
  77. // $sheet->setHeight=20;
  78. $sheet->getStyle('A:N')->getAlignment()->setHorizontal('center');
  79. $sheet->getColumnDimension('A')->setWidth(20);
  80. $sheet->getColumnDimension('B')->setWidth(20);
  81. $sheet->getColumnDimension('C')->setWidth(20);
  82. $sheet->getColumnDimension('D')->setWidth(20);
  83. $sheet->getColumnDimension('E')->setWidth(20);
  84. $sheet->getColumnDimension('F')->setWidth(20);
  85. $sheet->getColumnDimension('G')->setWidth(20);
  86. $sheet->getColumnDimension('H')->setWidth(20);
  87. $sheet->getColumnDimension('I')->setWidth(20);
  88. $sheet->getColumnDimension('J')->setWidth(20);
  89. $sheet->getColumnDimension('K')->setWidth(20);
  90. $sheet->getColumnDimension('L')->setWidth(20);
  91. $sheet->getColumnDimension('M')->setWidth(20);
  92. $sheet->getColumnDimension('N')->setWidth(20);
  93. },
  94. ];
  95. }
  96. }