Save To File

Topics: Developer Forum, Project Management Forum, User Forum
Aug 17, 2007 at 1:57 AM
Hi.
Great Library.
Sorry for my english.
I Just begin to use these classes, my question is as would manage to generate a file excel, reviews the classes and exists a called method "send", but single generates the headers, but not of where to obtain the data of the file excel generated so that the user can keep it.
Thanks for any help.

Best Regards.

Ruthsbel
Coordinator
Aug 17, 2007 at 7:36 AM
You need to send the necessary file headers, and afterwards use the writer of your choice. This has to write to 'php://output'.
Aug 17, 2007 at 4:06 PM
Thanks for the answer, I do not understand very well what you try me to say, which desire to obtain is something similar to this:

$filename = "test.xsl";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");

echo $dataExcel;

That the user can have the option to keep the file where wants, the function "save" , to keep single records it in a folder, and I want that the user can choose where to keep, I define the headers but i don`t know as to obtain the data from excel file generated.

Thanks for its commentaries.

Best Regards

Guillo.
Coordinator
Aug 20, 2007 at 7:07 AM
In the examples, you'll see this every once in a while:

$objWriter = new PHPExcelWriterExcel2007();
$objWriter->save( ...filename goes here...);

When you save to a normal filename, the file is saved to disk. When provided with 'php://output' as the filename, content is sent directly to the browser.
Aug 20, 2007 at 3:53 PM
It works!!!!!!!.

$filename = "test.xsl";
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 ");
$objWriter->save("php://output");

Thank you so much for your help.
Best Regards.
Guillo.
Oct 3, 2007 at 12:27 PM
Hi Guillo,

Your code $filename = "test.xsl"; header("Pragma: public"); .................... $objWriter->save("php://output"); did not work for me.
Are you sure, you did not forget something? I just "copy and paste" your code into the example 14excel5.php.

The browser suggest correctly to open the generated file in Excel, but the formatting of the opened document are totally wrong.
(Numbers, pictures etc. are not shown - only some binary code mixed with some plain text are shown.)

Best regards, Elund
Oct 3, 2007 at 4:24 PM
Hi Elund

This is my code:
//$dir, folder location of php classes

require($dir."/excel/Tests/05featuredemo.inc.php");
require($dir.'/excel/Classes/PHPExcel/Writer/Excel5.php');
$objWriter = new PHPExcelWriterExcel5($objPHPExcel);

$filename = "test.xls";
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 ");
$objWriter->save("php://output");

I hope that it works for you.

Regards.

Guillo.
Oct 4, 2007 at 2:00 AM
I'm having some issues with this. I'm able to get it to prompt me to download an excel file, but the file is just simple debugging text and nothing related to Excel and the worksheet. Any ideas?
Oct 4, 2007 at 7:42 AM
Hi Guillo,

Thanks for your prompt reply :-)

I had exactly the same code as you, but then I got the idea to remove all echo statements in the example and now it works! :-)

"dman", do you have the same issue?

Best regards, Elund
Oct 4, 2007 at 3:23 PM
Elund,
Thanks. I missed the echo's in the 14 demo include file.
Oct 4, 2007 at 3:37 PM
Hi Elund.

Yeah, you have to remove all 'echo', those they print to you what each object in the code does, sorry i forget about it.

Regards.

Guillo

Oct 19, 2007 at 4:25 AM
save('php://output') worked in Excel5 for me.
But in excel2007, the download is always empty.

Though the normal saving to a filename works for excel2007.
if "php://output" disabled for excel2007?

Using production 1.4.5
Coordinator
Oct 22, 2007 at 7:49 AM
For Excel2007, it is best to save to disk first and then use fpassthru() to sed it to the client.