Skip to content

Instantly share code, notes, and snippets.

@apfelbox
Last active December 14, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save apfelbox/5141771 to your computer and use it in GitHub Desktop.
Save apfelbox/5141771 to your computer and use it in GitHub Desktop.
PHPExcel + Symfony2
<?php
$participantModel = new ParticipantModel($this->container);
$filename = "participations_" . date("d_m_Y__H_i") . "_export.xls";
$excel = $participantModel->getExcelHandler();
$writer = \PHPExcel_IOFactory::createWriter($excel, "Excel5");
$handle = fopen("php://temp", "a");
$writer->save($handle);
rewind($handle);
$content = stream_get_contents($handle);
$response = new Response( $content );
$response->headers->set('Content-Type', 'application/vnd.ms-excel');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
@apfelbox
Copy link
Author

$participantModel->getExcelHandler() returns the (filled) excel object of type \PHPExcel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment