tags:

views:

60

answers:

1

Hi,

how to open excel file in browser ,

i dont want some thing like force download dialog ,

i want to open excel in browser somthing like in gmail when u click the excel file in the inbox, it will show browser itself,

same like , how to do in php.

+2  A: 

Using PHPExcel:

include 'PHPExcel/IOFactory.php';
$inputFileType = 'Excel5';
$inputFileName = 'MyExcelFile.xls';

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');
exit;

EDIT

If your Excel file is Excel 2007 (xlsx) or later rather than Excel 2003 (xls) or earlier

include 'PHPExcel/IOFactory.php';
$inputFileType = 'Excel2007';
$inputFileName = 'MyExcelFile.xlsx';

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');
exit;
Mark Baker
am getting error Fatal error: Uncaught exception 'Exception' with message 'The filename test.xlsx is not recognised as an
Bharanikumar
@Bharanikumar - If your file is Excel 2007 (xlsx) OpenXML format, then you need to use the appropriate reader, not the Excel5 BIFF reader of my initial example... see edit.
Mark Baker
For exact desig aspect like gmail, we should use any css or i should call any php classes (like excel grid )
Bharanikumar
@Bharanikumar - Write your own variant of the HTML Writer then, the existing code should provide the basis for what you want.
Mark Baker
@MarkBaker - thanks
Bharanikumar