Reputation: 113
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
Upvotes: 4
Views: 40854
Reputation: 191
This solved this issue for me:
$this->objWriter->save(str_replace(__FILE__,$_SERVER['DOCUMENT_ROOT'] .'/path/to/save/filename.xlsx',__FILE__));
Upvotes: 1
Reputation: 101
I solved this problem doing this:
$objWriter->save(str_replace(__FILE__,'/path/to/save/filename.extension',__FILE__));
In my case, it worked!
Upvotes: 10
Reputation: 17715
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');
Upvotes: 7
Reputation: 212412
Look at 01simple-download-xls.php in the PHPExcel Tests directory. This sends the Excel file to the user's browser, which then prompts them to either display it (in Excel if they have it installed, or other spreadsheet program if they have the extension associated with LibreOffice Calc or Gnumeric or whatever), or save it to their local disk.
Upvotes: 5