doubiaozhan0745 2014-08-27 12:35
浏览 445
已采纳

使用PHPExcel和PHPExcel_Writer_Excel2007在浏览器中显示excel文件

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');
?>
  • 写回答

1条回答 默认 最新

  • duanhuang2804 2014-08-27 12:53
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题