1、composer引入php处理excel包:box/spout
2、处理函数示例:
/** * @param string $filePath 文件绝对路径 * @return array * @throws */ public function readFromExcel(string $filePath) { $reader = ReaderEntityFactory::createXLSXReader(); $reader->open($filePath); $fileDataArr = []; foreach ($reader->getSheetIterator() as $sheet) { foreach ($sheet->getRowIterator() as $RowKey => $row) { if ($RowKey == 1) { continue; } foreach($row->getCells() as $CellKey => $value){ switch ($CellKey){ case 1: $orderId = $value->getValue(); break; default: case 0: $shopId = $value->getValue(); break; } } $fileDataArr[$shopId][] = $orderId; } break; } $reader->close(); return fileDataArr; }
TRANSLATE with