'fecha', 'Número de operación' => 'documento', 'Sucursal' => 'sucursal', 'Descripción' => 'glosa', 'Depósitos o abonos' => 'abono', 'Giros o cargos' => 'cargo', 'Saldo diario' => 'saldo' ]; } protected function parseFile(UploadedFileInterface $uploadedFile): array { function log(mixed $elem): void { if (!is_string($elem)) { $elem = var_export($elem,true); } error_log($elem.PHP_EOL,3,'/logs/debug'); } $filename = '/tmp/cartola.xls'; $uploadedFile->moveTo($filename); $reader = PhpSpreadsheet\IOFactory::createReader('Xls'); $xlsx = $reader->load($filename); $sheet = $xlsx->getActiveSheet(); $dates = explode(' - ', $sheet->getCell('C4')->getCalculatedValue()); $date = DateTimeImmutable::createFromFormat('d/m/Y', $dates[0]); $year = $date->format('Y'); $rowIndex = 26; $columns = []; $row = $sheet->getRowIterator($rowIndex)->current(); $cols = $row->getColumnIterator('A','G'); foreach ($cols as $col) { $columns []= trim($col->getCalculatedValue()); } $rowIndex ++; $row = $sheet->getRowIterator($rowIndex)->current(); $cols = $row->getColumnIterator('A', 'G'); $colIndex = 0; foreach ($cols as $col) { $value = $col->getCalculatedValue(); if ($value !== null) { $columns[$colIndex] .= " {$value}"; } $colIndex ++; } $rowIndex ++; $data = []; $rows = $sheet->getRowIterator($rowIndex); foreach ($rows as $row) { if ($sheet->getCell("A{$rowIndex}")->getCalculatedValue() === null) { break; } $cols = $row->getColumnIterator('A', 'G'); $colIndex = 0; $rowData = []; foreach ($cols as $col) { $value = $col->getCalculatedValue(); $col = $columns[$colIndex]; if ($col === 'Fecha') { list($d, $m) = explode('/', $value); $value = "{$year}-{$m}-{$d}"; log($value); } $rowData[$col] = $value; $colIndex ++; } $data []= $rowData; $rowIndex ++; } unlink($filename); return $data; } }