1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace App\Exports;
- use App\Models\User;
- use Illuminate\Support\Facades\Log;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\WithEvents;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithTitle;
- use Maatwebsite\Excel\Events\AfterSheet;
- class ExcelExport implements FromCollection, WithHeadings, WithEvents
- {
- public function collection()
- {
- return collect(
- [
- '2024年9月',
- '艳霞',
- '156****9339',
- '38',
- '',
- '38',
- '20',
- '760',
- '小温',
- '133****3328',
- '批发商',
- ]
- );
- }
- public function headings(): array
- {
- return['进货月份',
- '进货人(批发商)昵称',
- '进货人(批发商)手机号',
- '半醉浓香型件数',
- '半醉酱香型件数',
- '件数合计',
- '每件补助',
- '补助金额',
- '补助接收者昵称',
- '补助接收者手机号',
- '补助接收者身份'
- ];
- }
- public function setRowHeight(array $rouHeight)
- {
- $this->RowHeight=$rouHeight;
- }
- public function registerEvents(): array
- {
- return [
- AfterSheet::class => function(AfterSheet $event) {
- // 合并单元格,从 A1 到 C1
- $sheet = $event->sheet;
- // $sheet->mergeCells('A1:C1');
- // $sheet->setCellValue('A1','进货人信息');
- // 设置字体加粗、居中等样式
- $sheet->getStyle('A1')->getFont()->setBold(true);
- $sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
- // $sheet->mergeCells('D1:I1');
- // $sheet->setCellValue('D1','进货数量及金额');
- // 设置字体加粗、居中等样式
- $sheet->getStyle('D1')->getFont()->setBold(true);
- $sheet->getStyle('D1')->getAlignment()->setHorizontal('center');
- // $sheet->mergeCells('J1:L1');
- // $sheet->setCellValue('J1','拿补助的人信息');
- // 设置字体加粗、居中等样式
- $sheet->getStyle('J1')->getFont()->setBold(true);
- $sheet->getStyle('J1')->getAlignment()->setHorizontal('center');
- // $sheet->mergeCells('M1:N1');
- // $sheet->setCellValue('M1','补助明细及金额');
- $sheet->getStyle('M1')->getFont()->setBold(true);
- $sheet->getStyle('M1')->getAlignment()->setHorizontal('center');
- $sheet->getColumnDimension('B')->setWidth(20);
- $sheet->getColumnDimension('K')->setWidth(20);
- $sheet->setHeight=20;
- // $sheet->getStyle('A:N')->getAlignment()->setHorizontal('center');
- },
- ];
- }
- }
|