2017-08-23 4 views
0

Ceci est mon code. Le formulaire est soumis, mais aucun fichier n'est téléchargé en tant que pièce jointe. Aucune erreurTélécharger le fichier excel généré avec phpExcel en pièce jointe lorsque le formulaire est soumis en drupal 7

function dn_preorder_form_submit($form,&$form_state){ 
      $excel = new PHPExcel(); 
      $excel->setActiveSheetIndex(0); 
      $excel->getActiveSheet()->setCellValue('A1',"TEST"); 

      header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
      header('Content-Disposition: attachment; filename="var.xlsx"'); 
      header("Pragma: no-cache"); 
      header("Cache-Control: no-cache"); 
      header("Cache-Control: nmax-age=0"); 

      $file = PHPExcel_IOFactory::createWriter($excel,'Excel2007'); 

      $file->save('php://output'); 
} 

J'ai essayé cette solution https://drupal.stackexchange.com/questions/103690/download-file-on-form-submission Mais je reçois toujours mêmes résultats. j'ai essayé ce code extérieur drupal et il fonctionne

Répondre

0

OK, i résolu en insérant exit() à la fin du code

function dn_preorder_form_submit($form,&$form_state){ 
      $excel = new PHPExcel(); 
      $excel->setActiveSheetIndex(0); 
      $excel->getActiveSheet()->setCellValue('A1',"TEST"); 

      header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
      header('Content-Disposition: attachment; filename="var.xlsx"'); 
      header("Pragma: no-cache"); 
      header("Cache-Control: no-cache"); 
      header("Cache-Control: nmax-age=0"); 

      $file = PHPExcel_IOFactory::createWriter($excel,'Excel2007'); 

      $file->save('php://output'); 
      exit(); 
}