4

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

4 Answers 4

10

I solved this problem doing this:

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

In my case, it worked!

Sign up to request clarification or add additional context in comments.

1 Comment

I am getting ZipArchive::close() error while save phpexcel. $objWriter->save(str_replace(__FILE__,$excel_path,__FILE__));
7

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');

Comments

5

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.

1 Comment

I am getting ZipArchive::close() while save phpexcel. $objWriter->save($excel_path);
1

This solved this issue for me:

$this->objWriter->save(str_replace(__FILE__,$_SERVER['DOCUMENT_ROOT'] .'/path/to/save/filename.xlsx',__FILE__));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.