how to save('php://output') for /Tests/30template.php?

Topics: Developer Forum
Mar 21, 2012 at 1:15 PM
Edited Mar 21, 2012 at 1:50 PM

 in /Tests/30template.php use $objWriter->save(str_replace('.php', '.xls', __FILE__)) for save file,but I need download  on the browser 

when i used $objWriter->save('php://output') for download the 30template.xlsx, the OfficeExcel2007 have error  "您尝试打开的文件“30template.xlsx的格式与扩展名的格式不一致....

my code:

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

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

header('Cache-Control: max-age=0');

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

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

Mar 21, 2012 at 1:53 PM
Edited Mar 21, 2012 at 2:19 PM

It works:

require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/IOFactory.php';
                       
$objPHPExcel = PHPExcel_IOFactory::load("30template.xls");


header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="30template.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');

Mar 21, 2012 at 1:56 PM

i have use the header as your code

you can test , /Tests/30template.php

Mar 22, 2012 at 2:22 AM
Edited Mar 22, 2012 at 5:03 AM

yes, It works, Thank you! 

but my code doesn't work!

 

i know, in the MoreSelectSort.php have output . 

<?php
include_once($DOCUMENT_ROOT.'/include/staff_check');
include_once($DOCUMENT_ROOT.'/webservice/class/common/MoreSelectSort.php');