Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose location to save file excel with PHPExcel

Tags:

php

phpexcel

yii

I have a problem when using PHPExcel to create a excel file. I want to choose location to save file excel but I don't know how do it.

 $model = new User();
 $labels = $model->attributeNames();
 $data = $model->findAll();
 $objPHPExcel = Yii::app()->excel;

........
$filename = 'text.xlsx';
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($filename);

Please help me. thank you so much.

like image 377
Tam Vo Avatar asked Sep 07 '15 07:09

Tam Vo


3 Answers

Change the file name to desired path i.e,

$name = '/path/to/folder/xyz.xlsx';
$objWriter->save($name);

It Works For Me...

like image 106
Vatsal Patel Avatar answered Sep 28 '22 07:09

Vatsal Patel


$objWriter->save($filename);

.... change the value of $filename to be the filepath for wherever you want to save the file, e.g.

$filename = '/path/to/folder/test.xlsx';
$objWriter->save($filename);
like image 38
Mark Baker Avatar answered Sep 28 '22 07:09

Mark Baker


If you include below headers to your php file. Your users will have a download option pop-up:

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary ");
like image 37
Serhat Akay Avatar answered Sep 28 '22 08:09

Serhat Akay