}
$filename = 'actuality_' . date('Y-m-d') . '.xlsx';
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- header('Cache-Control: max-age=0');
+ $tempFile = tempnam(sys_get_temp_dir(), 'xlsx_');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
- $writer->save('php://output');
+ $writer->save($tempFile);
+
+ Yii::$app->response->sendFile(
+ $tempFile,
+ $filename,
+ ['mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
+ )->send();
+
+ @unlink($tempFile);
Yii::$app->end();
}