setReadDataOnly(true); $spreadsheet = $reader->load($filename); dump($spreadsheet); } public function index2() { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'Hello World !'); $sheet->setCellValue( 'A4', '=IF(A3, CONCATENATE(A1, " ", A2), CONCATENATE(A2, " ", A1))' ); $sheet->getCell('B8') ->setValue('Some value'); // Get the current date/time and convert to an Excel date/time $dateTimeNow = time(); $excelDateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow); $cellValue = $sheet->getCell('A4')->getValue(); $sheet->setCellValueByColumnAndRow(1, 5, 'PhpSpreadsheet'); dump($cellValue); $sheet->setCellValue( 'A6', $excelDateValue ); $sheet->setCellValue( 'A9', '0124578' ); echo date('Y-m-d H:i:s'); $sheet->getStyle('A6') ->getNumberFormat() ->setFormatCode( 'yyyy-mm-dd' ); $sheet->setCellValueExplicit( 'A8', "01513789642", \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING ); /*$sheet->getStyle('A9') ->getNumberFormat() ->setFormatCode( '0000000' );*/ $dataArray = $sheet ->rangeToArray( 'A4:A6', // The worksheet range that we want to retrieve NULL, // Value that should be returned for empty cells TRUE, // Should formulas be calculated (the equivalent of getCalculatedValue() for each cell) TRUE, // Should values be formatted (the equivalent of getFormattedValue() for each cell) 1 // Should the array be indexed by cell row and cell column ); dump($dataArray); $writer = new Xlsx($spreadsheet); $filename = to_linux_path(public_path()) . '/phpoffice/world' . mt_rand(1000, 999999999) . '.xlsx'; $writer->save($filename); } }