4

xlsx file not download in IE but properly work in firefox my code is

$objPHPExcel->setActiveSheetIndex(0);

// Redirect output to a client’s web browser (Excel2007)

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

header("Content-Disposition: attachment;filename='Monthly-Report-$month-$year'");

header('Cache-Control: max-age=0');



$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

$objWriter->save('php://output');
//$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
exit;

error message shows in IE as internet explorer cannot download xlsx.php(this is my php file in which code is written) Internet explorer was not able to open this site

  • 2
    Are you using SSL? There's an issue with the Cache-control headers with SSL as this support kb article sums up - http://support.microsoft.com/kb/323308. Additionally, you can check a similar response posted here on SO - http://stackoverflow.com/questions/2232103/how-do-i-get-csv-file-to-download-on-ie-works-on-firefox. You may just need to tweak the headers and I think you'll be good if you are trying this over SSL. – verisimilitude May 30 '12 at 08:29

2 Answers2

3

Yes, if you're on HTTPS it will be problem with Internet Explorer. You need to remove the Pragma header from your response while you're processing the file download.

Before download put following code:

header("Pragma: ");

This will be the case only if you're running with secure http, let us know if that's not the case.

You may find more description over my blog post which I wrong while I faced same problem over https while it was working perfect for http on IE.

http://blogs.digitss.com/programming/internet-explorer-was-not-able-to-open-this-internet-site-the-requested-site-is-either-unavailable-or-cannot-be-found/

I hope this helps.

deej
  • 2,536
  • 4
  • 29
  • 51
-1

use application/vnd.ms-excel instead of application/vnd.openxmlformats-officedocument.spreadsheetml.sheet for backward compatibility.

if you have the right to modify the mime settings of your web server, you need to add AddType application/vnd.openxmlformats .docx .pptx .xlsx AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx to your, for example, apache conf.

afterwards, change your file name to Monthly-Report-$month-$year.xlsx instead.

Abby Chau Yu Hoi
  • 1,378
  • 3
  • 15
  • 37
  • 1
    application/vnd.ms-excel is for BIFF format xls files, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet is for OfficeOpenXML xlsx files.... thsi is nothing to do with backward compatibility. OP Is using the correct Content-Type for his file. You're telling him to use a wrong type for a totally spurious reason – Mark Baker May 30 '12 at 08:47
  • I know the type is wrong, but it is a workaround, because one of the terminals may not have it installed. – Abby Chau Yu Hoi May 30 '12 at 08:58
  • 1
    It's nothing to do with server mime type settings, it's all to do with the headers being sent to the browser.... this isn't a workround, it's just wrong – Mark Baker May 30 '12 at 09:04