如何在浏览器中打开excel文件,
我不想要像强制下载对话框那样的东西,
当我点击收件箱中的excel文件时,我想在浏览器中打开excel,就像在gmail中一样,它会显示浏览器本身,
同样如何在php中做。
答案 0 :(得分:10)
使用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;
修改强>
如果您的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;