Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 24 |
| WaybillExport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
42.00 | |
0.00% |
0 / 24 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| collection | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 11 |
|||
| columnFormats | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| <?php | |
| namespace App\Exports; | |
| use Maatwebsite\Excel\Concerns\FromCollection; | |
| use Maatwebsite\Excel\Concerns\ShouldAutoSize; | |
| use Maatwebsite\Excel\Concerns\WithColumnFormatting; | |
| use Maatwebsite\Excel\Concerns\WithCustomValueBinder; | |
| use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder; | |
| use PhpOffice\PhpSpreadsheet\Style\NumberFormat; | |
| class WaybillExport extends StringValueBinder implements FromCollection,ShouldAutoSize,WithColumnFormatting,WithCustomValueBinder | |
| { | |
| private $row; | |
| private $data; | |
| public function __construct($row,$data) | |
| { | |
| $this->row = $row; | |
| $this->data = $data; | |
| } | |
| public function collection() | |
| { | |
| $row = $this->row; | |
| $data = $this->data; | |
| //设置表头 | |
| foreach ($row[0] as $key => $value) { | |
| $key_arr[] = $key; | |
| } | |
| //输入数据 | |
| foreach ($data as $key => &$value) { | |
| $js = []; | |
| for ($i=0; $i < count($key_arr); $i++) { | |
| $js = array_merge($js,[ $key_arr[$i] => $value[ $key_arr[$i] ] ]); | |
| } | |
| array_push($row, $js); | |
| unset($val); | |
| } | |
| return collect($row); | |
| } | |
| public function columnFormats(): array{ | |
| return [ | |
| 'D' => NumberFormat::FORMAT_TEXT, | |
| 'H' => NumberFormat::FORMAT_TEXT, | |
| 'I' => NumberFormat::FORMAT_TEXT, | |
| 'L' => NumberFormat::FORMAT_TEXT, | |
| 'O' => NumberFormat::FORMAT_TEXT, | |
| 'Q' => NumberFormat::FORMAT_TEXT, | |
| 'S' => NumberFormat::FORMAT_TEXT, | |
| 'T' => NumberFormat::FORMAT_TEXT, | |
| 'U' => NumberFormat::FORMAT_TEXT, | |
| 'V' => NumberFormat::FORMAT_TEXT, | |
| ]; | |
| } | |
| } | |