What's wrong my code please any one help

What's wrong my code please any one help
0

Browser Download not work.

   public function exportToExcel($report=array(),$year=array())
    {

        // pr($report);
        /// die;
        
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $spreadsheet->setActiveSheetIndex(0);
        $drawing = new Drawing();

        $drawing->setName('chart');
        $drawing->setDescription('chart');
        // debug($image_name);
         //$filename = '/var/www/html/canqualify-new/images/img/image.png';
        //if (file_exists($filename)) {          
          
        $drawing->setPath('/var/www/html/canqualify-new/images/img/image.png'); // put your path and image here
        
        $drawing->setCoordinates('A4');
        $drawing->setOffsetX(110);
        $drawing->setRotation(25);
        $drawing->getShadow()->setVisible(true);
        $drawing->getShadow()->setDirection(45);
        $drawing->setWorksheet($spreadsheet->getActiveSheet());
        $spreadsheet->getActiveSheet()->setTitle('chart');
        
        
        // Rename worksheet        
        $spreadsheet->createSheet();
        // Add some data
        /* Header for Worksheet Table */ 
         $i=67;
         if($i <= 70)
         {
        foreach ($year as $key => $value) {         
        
        $spreadsheet->setActiveSheetIndex(1)
                ->setCellValue('A1','Contractor Name')
                ->setCellValue('B1','Category'); 
                $azRange = range('C', 'F');
                    //pr($value);
                
                  $spreadsheet->setActiveSheetIndex(1)->setCellValue(chr($i).'1',$value);
        
                 $i++;  
        }
        }          
        /* End */ 
        //$spreadsheet->getActiveSheet(1)->fromArray($report,NULL,'A2');
         
        /*  Data putting in the worksheet  */        
         $col = 2;
         foreach ($report as $rep) {
            $row = 1;
        //  pr($rep);
                foreach ($rep as $key => $value) {
                    $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($row, $col, $value);                 
                     // pr($value);
                   $row++;
                }
               $col++;
         }
         /*  End   */     
         
        $spreadsheet->getActiveSheet()->setTitle('Table');        
        $writer = new Xlsx($spreadsheet);
        // Redirect output to a client's web browser (Xlsx)

        $filename = 'Report';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="'. $filename .'.xls"'); /*-- $filename is  xsl filename ---*/
        header('Cache-Control: max-age=0');
         
        $Excel_writer->save('php://output');
        return true;
     
    }

Browser download not working Please help me out this problem . when i call this function i want download the file.that’s it otherwise function will work fine