vehicleModel = $vehicleModel; } /** * 设置头部 * * @time 2020年09月08日 * @return string[] */ public function headers(): array { // TODO: Implement headers() method. return [ '部门','车牌号码','车辆状态','车主姓名','车辆品牌','车辆颜色', '上牌时间','上牌员工','电机号','车架号','购买日期','备注' ]; } /** * 处理数据 * * @time 2020年09月08日 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @return \think\Collection */ public function sheets() { $list = $this->vehicleModel->getVehiclesExportList(); foreach ($list as &$val) { $val->frame_number ="\t".$val->frame_number."\t"; $val->motor_number ="\t".$val->motor_number."\t"; } return $list; } public function keys(): array { // TODO: Implement keys() method. return [ 'depart_name','license_plate','vehicle_state','owner','brand_name','color_name','license_time','open_user_name','motor_number','frame_number','buydate','remark' ]; } /** * 设置开始行 * * @time 2020年09月08日 * @return int */ public function setRow() { return 2; } /** * 设置标题 * * @time 2020年09月08日 * @return array */ public function setTitle() { return [ 'A1:I1', '导出车辆', Alignment::HORIZONTAL_CENTER ]; } /** * 设置宽度 * * @time 2020年09月08日 * @return array */ public function setWidth() { return [ 'A' => 20, 'B' => 20, 'C' => 20, 'D' => 20, 'E' => 20, 'F' => 20, 'G' => 30, 'H' => 20, 'I' => 30, 'J' => 30, 'K' => 30, 'L' => 30, ]; } public function getWorksheet($sheet) { // $sheet->getStyle('B')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT); // $sheet->getColumnDimension('B')->setAutoSize(true); // $sheet->getColumnDimension('C')->setAutoSize(true); // $sheet->getColumnDimension('D')->setAutoSize(true); // $sheet->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); // $sheet->getActiveSheet()->getColumnDimension('D')->setAutoSize(true); return $sheet; } }