php php在浏览器中打开excel文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3861397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:20:05  来源:igfitidea点击:

php open excel file in browser

phpcom

提问by Bharanikumar

how to open excel file in browser ,

如何在浏览器中打开excel文件,

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,

我想在浏览器中打开 excel,就像在 gmail 中一样,当您单击收件箱中的 excel 文件时,它会显示浏览器本身,

same like , how to do in php.

一样,如何在 php.ini 中做。

回答by Mark Baker

Using PHPExcel:

使用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

如果您的 Excel 文件是 Excel 2007 (xlsx) 或更高版本,而不是 Excel 2003 (xls) 或更低版本

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;