php open excel file in browser

2019-01-24 12:14发布

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.

标签: php com
1条回答
我只想做你的唯一
2楼-- · 2019-01-24 13:05

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;
查看更多
登录 后发表回答