I am using the 05featuredemo.php
example of the phpexcel, which is downloaded from the codeplex Latest Built PHPExcel_1.8.0_doc
by MarkBaker ( SO )
The point i need i look is
$objWriter->save(str_replace('.php', '.xls', __FILE__));
Above is used for saving the file in the script location, But How can i make it as simple downloadable.
I tried with
$objWriter->save('php://output');
But It didn't download the file that is generated. How can i do that, Is there any other thing i should do ?
If you're sending anything other than straight HTML to a browser, then you need to send the appropriate headers so that the browser can know how to handle it.
There is a section of the developer documentation entitled Redirect output to a client's web browser that explains this, and it's also demonstrated in examples like 01simple-download-xls.php
and 01simple-download-xlsx.php
If you want to give name by yourself then you can specify as I have specified in $a
.
I wanted to use a filename from where this function is being called so I concat that name to the excel filename and also attached current date to the filename.
Note: LogReport
is a folder where my files will be downloaded.
self::$objPHPExcel = new PHPExcel();
$objWriter = PHPExcel_IOFactory::createWriter(self::$objPHPExcel, 'Excel2007');
$a = 'Log' . self::$filename . date("Y-m-d") . '.xlsx';
$objWriter->save(__DIR__ . '/LogReport/' . $a);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.