Skip to content

Instantly share code, notes, and snippets.

@vincentmoulene
Created May 2, 2018 15:42
Show Gist options
  • Save vincentmoulene/bbbdfe2b452a7a4e5cab21a201f9c67c to your computer and use it in GitHub Desktop.
Save vincentmoulene/bbbdfe2b452a7a4e5cab21a201f9c67c to your computer and use it in GitHub Desktop.
Export xls with symfony
use Symfony\Component\HttpFoundation\Request;
/**
* Create a zip file with excel contain the list of clubs.
*
* @param Request $request
* @param $the_response_excel_file
* @param $the_file_name
*/
public function exportAction(Request $request, $the_response_excel_file, $the_file_name)
{
// adding headers
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$filename
);
$response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
return $response;
}
@pdalfarr
Copy link

I think 'text/vnd.ms-excel' mimetype does not exist. It should be 'application/vnd.ms-excel'.
See https://github.com/apache/tika/blob/main/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml#L1898

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