setReadDataOnly(true); $spreadsheet = $reader->load($file); } catch (\Exception $e) { Dever::error('加载文件发生错误:"'.$file.'": ' . $e->getMessage()); } $sheet = $spreadsheet->getSheet($sheetIndex); $highestRow = $sheet->getHighestRow(); $highestCol = $sheet->getHighestColumn(); $columnCnt = array_search($highestCol, $this->cell) ?: 0; $draws = $sheet->getDrawingCollection(); $pictures = []; foreach ($draws as $img) { list($col, $row) = Coordinate::coordinateFromString($img->getCoordinates()); $pictures[$row][$col][] = Dever::load('save', 'upload')->init(1)->act($img->getPath())['url']; } for ($row = $offset + 1; $row <= $highestRow; $row++) { $rowData = []; for ($col = 0; $col <= $columnCnt; $col++) { $key = $this->cell[$col]; if (isset($pictures[$row][$key])) { $cellValue = $pictures[$row][$key]; } else { $cellId = $key . $row; $cellValue = $sheet->getCell($cellId)->getCalculatedValue(); if ($cellValue instanceof RichText) { $cellValue = $cellValue->__toString(); } } if ($head && $key = Dever::issets($head, $col)) { if (is_array($key)) { $rowData[$key[0]][$key[1]] = $cellValue; } else { $rowData[$key] = $cellValue; } } else { $rowData[$key] = $cellValue; } } yield $rowData; } } } /* setReadDataOnly(true); $excel = $read->load($file); } catch (\Exception $e) { Dever::error('加载文件发生错误:"'.$file.'": '. $e->getMessage()); } $sheet = $excel->getSheet($sheet); $columnH = $sheet->getHighestColumn(); $columnCnt = array_search($columnH, $this->cell); if (!$columnCnt) { $columnCnt = $offset - 1; } if ($columnCnt < 0) { $columnCnt = 0; } $rowCnt = $sheet->getHighestRow(); $data = array(); for ($_row = 1; $_row <= $rowCnt; $_row++) { for ($_column = 0; $_column <= $columnCnt; $_column++) { $cellId = $this->cell[$_column].$_row; //$cellValue = $sheet->getCell($cellId)->getValue(); $cellValue = $sheet->getCell($cellId)->getCalculatedValue(); if ($cellValue instanceof \PhpOffice\PhpSpreadsheet\RichText\RichText) { $cellValue = $cellValue->__toString(); } $data[$_row][$this->cell[$_column]] = $cellValue; } } $draws = $sheet->getDrawingCollection(); //处理图片 foreach ($draws as $img) { list($startColumn, $startRow) = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::coordinateFromString($img->getCoordinates());//获取图片所在行和列 $pic = Dever::load('save', 'upload')->act(1, $img->getPath()); //插入代码 //$startColumn = $this->decimal($startColumn);//由于图片所在位置的列号为字母,转化为数字 $data[$startRow][$startColumn] = $pic['url']; } return $data; } } */