ciao!

in sostanza devo creare una funzione che, inviato un form, mi crea un file xlsx e lo scarica.
ho installato phpspreadsheet e fatto questo (in realtà questo è l'ultimo test che ho fatto):
codice:
      <form method="post" action="" class="container-fluid">
        <?php
        if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['btn_esporta'])) {
          $spreadsheet = new Spreadsheet();


          $spreadsheet
              ->getProperties()
              ->setCreator('The Space Cinema')
              ->setLastModifiedBy('The Space Cinema')
              ->setTitle('The Space Cinema')
              ->setSubject('The Space Cinema')
              ->setDescription('The Space Cinema');


          $spreadsheet->setActiveSheetIndex(0)
              ->setCellValue('A1', 'Hello')
              ->setCellValue('B2', 'world!')
              ->setCellValue('C1', 'Hello')
              ->setCellValue('D2', 'world!');


          header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
          header('Content-Disposition: attachment;filename="contest.xlsx"');
          header("Pragma: no-cache");
          header("Expires: 0");


          $fileName = get_content_dir() . 'contest.xlsx';
          $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
          ob_end_clean();
          $writer->save('php://output');
        }
        ?>
        <button type="submit" name="btn_esporta" class="btn btn-success btn-lg">Esporta in XLS</button>
      </form>
il problema è che non scarica il file, ma visualizza i dati binari su pagina.
come posso forzare il download del file??