在浏览器中显示Excel文件. PHPExcel

例如,我正在使用这样的代码:

<?php

    require_once("D:\server/www/cls/PHPExcel.php");
    require_once("D:\server/www/cls/PHPExcel/IOFactory.php");

    $objPHPExcel = new PHPExcel();

    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B2', 'HeaderB');    
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('C2', 'HeaderC');
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('D2', 'HeaderD');    
    ob_end_clean();

    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="report.xlsx"');

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    ob_end_clean();

    $objWriter->save('php://output');
?>

它会下载report.xlsx文件,并且不会在浏览器中显示它.我该怎么做?

谢谢!

解决方法:

删除此行…

header('Content-Disposition: attachment;filename="report.xlsx"');

用户在浏览器中还必须具有能够查看Excel文件的内容.

上一篇:关于PHPExcel图表的一些问题


下一篇:在php中按一定值递增数字之类的字母