getActiveSheet(); // Set the value of cell A1 $sheet->setCellValue('A1', 'GeeksForGeeks!'); // Sets the value of cell B1 $sheet->setCellValue('B1', 'A Computer Science Portal For Geeks'); // Write an .xlsx file $writer = new Xlsx($spreadsheet); // Save .xlsx file to the current directory $writer->save('gfg.xlsx'); $fileName="abc.xlsx"; $writer = new Xlsx($spreadsheet); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="'. urlencode($fileName).'"'); $writer->save('php://output'); ?>