| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 3 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 24
WaybillExport | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 3 | 42.00 | 0.00% covered (danger) | 0.00% | 0 / 24
__construct | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 3
collection | 0.00% covered (danger) | 0.00% | 0 / 1 | 20.00 | 0.00% covered (danger) | 0.00% | 0 / 11
columnFormats | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 10

1 | <?php
2 | namespace App\Exports;
3 | use Maatwebsite\Excel\Concerns\FromCollection;
4 | use Maatwebsite\Excel\Concerns\ShouldAutoSize;
5 | use Maatwebsite\Excel\Concerns\WithColumnFormatting;
6 | use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
7 | use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
8 | use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
9 |
10 | class WaybillExport extends StringValueBinder implements FromCollection,ShouldAutoSize,WithColumnFormatting,WithCustomValueBinder
11 | {
12 | private $row;
13 | private $data;
14 |
15 | public function __construct($row,$data)
16 | {
17 | $this->row = $row;
18 | $this->data = $data;
19 | }
20 |
21 | public function collection()
22 | {
23 | $row = $this->row;
24 | $data = $this->data;
25 |
26 | //设置表头
27 | foreach ($row[0] as $key => $value) {
28 | $key_arr[] = $key;
29 | }
30 |
31 | //输入数据
32 | foreach ($data as $key => &$value) {
33 | $js = [];
34 | for ($i=0; $i < count($key_arr); $i++) {
35 | $js = array_merge($js,[ $key_arr[$i] => $value[ $key_arr[$i] ] ]);
36 | }
37 | array_push($row, $js);
38 | unset($val);
39 | }
40 | return collect($row);
41 | }
42 | public function columnFormats(): array{
43 | return [
44 | 'D' => NumberFormat::FORMAT_TEXT,
45 | 'H' => NumberFormat::FORMAT_TEXT,
46 | 'I' => NumberFormat::FORMAT_TEXT,
47 | 'L' => NumberFormat::FORMAT_TEXT,
48 | 'O' => NumberFormat::FORMAT_TEXT,
49 | 'Q' => NumberFormat::FORMAT_TEXT,
50 | 'S' => NumberFormat::FORMAT_TEXT,
51 | 'T' => NumberFormat::FORMAT_TEXT,
52 | 'U' => NumberFormat::FORMAT_TEXT,
53 | 'V' => NumberFormat::FORMAT_TEXT,
54 | ];
55 | }
56 | }
57 |