Yii v2 snippet guide II

Comparing #11 with #12

Revision #12 was created by rackycz rackycz on Sep 8, 2020, 7:14:04 PM.

Composer and PhpExcel

Content

[...]
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xlsx($spreadsheet);

//
will be saved in "web" folder
 
$writer->save('hello world
You can save the file on the server:
 
// $writer->save('hello world.xlsx'); 
 
 
// Or you can send the file directly to the browser so user can download it:
 
//header('Content-Type: application/vnd.ms-excel'); // This is probably for older XLS files.
 
header('Content-Type: application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); // This is for XLSX files (they are basically zip files).
 
header('Content-Disposition: attachment;filename="filename
.xlsx"'); 
 
$writer->save($outputFileName);
 
exit();
```