2

I have an HTML link that launches a PHP script :

<a id="exportExcel" href = 'PHPScript.php'>Dowload File</a>

This link doesn't open any other windows. It just creates and sends an Excel File to the user (Using phpExcel).

   //Include the PHPExcel library
   include ('/lib/PHPExcel/PHPExcel.php');
   include ('/lib/PHPExcel/PHPExcel/IOFactory.php');

   //Create a new Excel File
   $objPHPExcel = new PHPExcel();
   $objPHPExcel->setActiveSheetIndex(0);
   $sheet = $objPHPExcel->getActiveSheet();

   $indiceColumn = "A";
   $indiceLine = 1;

   //Put data in the ExcelFile
   $listColumnName = mysql_query("select * FROM  my_table WHERE config = ".$id_config." ORDER BY id");
   while($columnName = mysql_fetch_object($listColumnName))
   {
      $sheet->SetCellValue($indiceColumn.$indiceLine, $columnName->csv_nom_col);
      $indiceColumn++;
   }

   //Send the file to the user
   $writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');  
   header('Content-Type: application/application/vnd.ms-excel');
   header('Content-Disposition: attachment;filename="template.xls"');
   header('Cache-Control: max-age=0');
   $writer->save('php://output');

But it takes some time to create the file, so I have a loadBar that's shown when the user clicks on my link.

   $("#exportExcel").click(function()
   {
      $("#loadBar").show();
   });

It's works, but I don't know when I have to hide it. What I want is to hide the loadBar when the user receivea the file or when the PHPScript is finished.

cweiske
  • 30,033
  • 14
  • 133
  • 194
Kvasir
  • 1,197
  • 4
  • 17
  • 31

0 Answers0