composer.json
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "~2.0.14",
"phpoffice/phpspreadsheet": "^1.6"
},
controller
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
//输出
// example
// $objPHPExcel = new \PHPExcel();
// $objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
// // Add some data
// $objPHPExcel->setActiveSheetIndex(0)
// ->setCellValue('A1', 'Hello')
// ->setCellValue('B1', 'world!')
// ->setCellValue('C1', 'Hello')
// ->setCellValue('D1', 'world!');
// // Rename worksheet
// $objPHPExcel->getActiveSheet()->setTitle('Simple');
// // Set active sheet index to the first sheet, so Excel opens this as the first sheet
// $objPHPExcel->setActiveSheetIndex(0);
// // Redirect output to a client’s web browser (Excel5)
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Disposition: attachment;filename="01simple.xls"');
// header ('Pragma: public'); // HTTP/1.0
// $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
// $objWriter->save('php://output');
// exit;
(adsbygoogle = window.adsbygoogle || []).push({});