Php – Displaying excel file in a browser using PHPExcel and PHPExcel_Writer_Excel2007

browserPHPphpexcel

Issue regarding displaying excel content in browser without asking to save the attachment.
I can open excel file download via attachment. But can't get show it in browser.

$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
//$writer =  PHPExcel_IOFactory::createWriter();
ob_end_clean();
header('Content-Type: application/vnd.openxmlformats-  officedocument.spreadsheetml.sheet');
ob_end_clean();
$writer->save('php://output');
exit;   

this is same to
Displaying excel file in a browser. PHPExcel

@helicera: You will need to give the filename the xlsx extension. – alex Jan 18 '12 at 7:05

But where can I give xlsx extention after removing
header('Content-Disposition: attachment;filename="report.xlsx"');
line ?

======================== from loading excel ==================

<?php
error_reporting(E_STRICT);
require_once 'PHPExcel.php';
require_once 'PHPExcel/Writer/Excel2007.php';
require_once 'PHPExcel/IOFactory.php';
$inputFileName = 'example.xls';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('example.html');
?>

Best Answer

You can't get a native format Excel file to show in a browser.... web browsers will render HTML markup, and can display images in various formats, but not other arbitrary file formats.

If you want to show an Excel file in a web browser, you will need to use PHPExcel's HTML Writer, which will generate HTML markup that a browser is capable of displaying

Related Topic