34k+
News
Guide
API
Wiki
Forum
Community
Places
Members
Hall of Fame
Badges
More
Learn
Books
Resources
Develop
Download Yii
Extensions
Report an Issue
Report a Security Issue
Contribute to Yii
Donate
About
Release Cycle
License
Team
Official Logos and Design
Login
Yii v2 snippet guide II
Comparing
#18
with
#19
Revision #19 was created by
rackycz
on Sep 8, 2020, 7:39:51 PM.
Composer and PhpExcel
« Previous (#18)
Next (#20) »
Content
[...]
header('Cache-Control: max-age=0');
$writer->save('php://output');
exit();
```
Thanks to [DbCreator](https://forum.yiiframework.com/t/yii2-phpoffice-phpspreadsheet-src-phpspreadsheet-shared-ole-pps-root-php-on-line-292-headers-already-sent/126617) for the latter approach.
Other ways did not work for me.
Following is my idea:
```php
ob_start();
ob_implicit_flush(false);
$writer->save($outputFileName);
$file = ob_get_clean();
return \Yii::$app->response->sendContentAsFile($file, 'file.xlsx',[
'mimeType' => 'application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'inline' => false
]);
```