load($inputFileName); $sheet = $spreadsheet->getActiveSheet(); $i = 2; $sum_format = '#,##0.00\ "₽";[Red]\-#,##0.00\ "₽"'; foreach ($products as $product) { $sheet->setCellValue('B' . $i, $product->name_tz); $sheet->setCellValue('C' . $i, $product->type_tz); $sheet->setCellValue('D' . $i, $product->nomenclature_number); $sheet->setCellValue('E' . $i, $product->sizes); $sheet->setCellValue('F' . $i, $product->manufacturer); $sheet->setCellValue('G' . $i, $product->unit); $sheet->setCellValue('H' . $i, $product->type); $sheet->setCellValue('I' . $i, $product->price_status); $sheet->setCellValue('J' . $i, $product->product_price); $sheet->setCellValue('K' . $i, $product->installation_price); $sheet->setCellValue('L' . $i, $product->service_price); $sheet->setCellValue('M' . $i, $product->total_price); $sheet->setCellValue('N' . $i, $product->manufacturer_name); $sheet->setCellValue('O' . $i, $product->article); $sheet->setCellValue('P' . $i, $product->note); $sheet->getStyle("J{$i}:M{$i}")->getNumberFormat()->setFormatCode($sum_format); $i++; } $fileName = 'product_export_' . date('Y-m-d_H-i-s') . '.xlsx'; $writer = new Xlsx($spreadsheet); $writer->save(storage_path('app/public/export') . '/' . $fileName); return $fileName; } }