Akhilesh Thakur
Akhilesh Thakur

Reputation: 51

Trying to download xlsx 2007 file in Internet Explorer

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

Upvotes: 4

Views: 3607

Answers (2)

deej
deej

Reputation: 2564

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.

Upvotes: 3

Abby Chau Yu Hoi
Abby Chau Yu Hoi

Reputation: 1398

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.

Upvotes: -1

Related Questions