Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel save file in a folder or open excel

Tags:

php

phpexcel

I am using PHPExcel to export data from my PHP page to Excel. I am using Excel5.

I want the excel file to be be saved a particular folder that is specified in the code

OR better still,

I want Excel to open with the data written in it so that user can save it wherever he wants. What should I do.

Please guide me

Pre

like image 626
Pre Avatar asked Nov 29 '22 17:11

Pre


2 Answers

I solved this problem doing this:

$objWriter->save(str_replace(__FILE__,'/path/to/save/filename.extension',__FILE__));

In my case, it worked!

like image 52
Filipe Synthis Avatar answered Dec 10 '22 11:12

Filipe Synthis


This will ask the user to save / open the file:

$excel = new PHPExcel();
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="your_name.xls"');
header('Cache-Control: max-age=0');
// ...
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5);
$writer->save('php://output');
like image 21
matino Avatar answered Dec 10 '22 11:12

matino