Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3927

Download PhpSpreadsheet file without save it before

$
0
0

I'm using PhpSpreadsheet to generate an Excel file in Symfony 4. My code is:

$spreadsheet = $this->generateExcel($content);

$writer = new Xlsx($spreadsheet);
$filename = "myFile.xlsx";
$writer->save($filename); // LINE I WANT TO AVOID
$response = new BinaryFileResponse($filename);
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$response->setContentDisposition(
    ResponseHeaderBag::DISPOSITION_ATTACHMENT,
    $filename
);

But I don't want to save the file and then read it to return to the user. I would like to download Excel content directly. Is there a way to do It?

I've searched how to generate a stream of the content (as this answer says) but I hadn't success.

Thanks in advance and sorry about my English


Viewing all articles
Browse latest Browse all 3927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>