Save a xls file in a custom folder

Topics: Developer Forum
Sep 17, 2010 at 2:37 PM

Good morning!

In first place, sorry for my poor English, I´m from Brazil.

I´m trying to save a .xls file generated by PHPExcel class in a different folder of where is located my .php file.

For example: I have a file in /relatorios/paulo.php and I want to save the .xls file in other folder... /example/somefile.xls

Is it possible?

 

Thanks to everybody!

Coordinator
Sep 17, 2010 at 2:43 PM
$objWriter->save('/save/to/whatever/folder/you/want/filename.xls');
Sep 17, 2010 at 3:02 PM

Hi Mark!

Thanks for your reply.

I try to change my code and it isn´t work.

Example:

    // Export to Excel5 (.xls)
   echo date('H:i:s') . " Write to Excel5 format\n";
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('/example/of/folder/to/save/teste.xls');

The follow error message appears:

Fatal error: Uncaught exception 'Exception' with message 'Could not close zip file /usr/apache/htdocs/ntkonline/cadastros/teste.xlsx.' in /usr/apache/htdocs/ntkonline/relatorios/1.7.4/Classes/PHPExcel/Writer/Excel2007.php:340 Stack trace: #0 /usr/apache/htdocs/ntkonline/relatorios/numeros_logicos.php(668): PHPExcel_Writer_Excel2007->save('/usr/apache/htd...') #1 /usr/apache/htdocs/ntkonline/relatorios/numeros_logicos.php(126): geraExcel() #2 {main} thrown in /usr/apache/htdocs/ntkonline/relatorios/1.7.4/Classes/PHPExcel/Writer/Excel2007.php on line 340

 

Coordinator
Sep 17, 2010 at 3:21 PM

The Excel2007 Writer will typically throw this exception if a file of the same name already exists: that particular writer won't overwrite. Delete any existing file before saving.

Sep 17, 2010 at 3:40 PM

It works!

I´ve change the destination folder´s permission.

 

Thanks!

Nov 21, 2013 at 8:47 AM
Is there any way to be able to write Excel file without giving destination folder´s full permissions. 777
Apr 3, 2014 at 8:26 AM
How to save in browser?
Coordinator
Apr 4, 2014 at 6:03 PM
@gsivaprabu By following the Examples given, such as 01simple-download-xls.php and 01simple-download-xlsx.php
Aug 28, 2014 at 1:24 PM
Edited Aug 28, 2014 at 1:24 PM
Hi!

I know is to late to answer to you, but maybe someone else will be reading this topic.
I've used somthing like that in my project to get excel as file to save in browser:
        // Redirect output to a client’s web browser (Excel2007)
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="' . $config['object'] . time() . '.xlsx"');
        header('Cache-Control: max-age=0');
        // If you're serving to IE 9, then the following may be needed
        header('Cache-Control: max-age=1');

        // If you're serving to IE over SSL, then the following may be needed
//      header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
        header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header('Pragma: public'); // HTTP/1.0


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


        // Echo done
        $this->_helper->layout->disableLayout(); //in ZendFramework
        $this->_helper->viewRenderer->setNoRender(); //in ZendFramework
        header('Content-type: application/vnd.ms-excel');
Hope it's usefull.