When generating worksheet save it to the server

Asked

Viewed 674 times

0

Hello, I am generating an Excel table using the Phpexcel class, so it generated forced the download, only now I want to generate it save on the server instead of force the download directly, I did not find in the documentation, the part that forces the download

header('Content-Disposition: attachment;filename="planilha.xls"');
$objWriter->save('php://output');
  • just use $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); and then $objWriter->save(diretorio/planilha.xls);. The second parameter of createWriter is the version that will be saved, in this case for files . xls uses Excel5, to save . xlsx use Excel2007.

  • Thanks friend, so solved, like the reply of William

1 answer

1


Just remove the:

header('Content-Disposition: attachment;filename="planilha.xls"');

And change this:

$objWriter->save('php://output');

For something like this:

$objWriter->save('pasta/foo/baz.pdf');

So it will save in a folder on the server, if you want to save and download at the same time, you can use:

header('Content-Disposition: attachment;filename="planilha.xls"');
$objWriter->save('php://output');

copy('php://output', 'pasta/foo/baz.pdf');

Or use (not tested, but the doc does not impose any restriction):

header('Content-Disposition: attachment;filename="planilha.xls"');
$objWriter->save('pasta/foo/baz.pdf');
$objWriter->save('php://output');
  • 1

    It worked, thanks buddy.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.