| | | | | | | | | | | | | | public function _export($data,$title){ | | | | | | | | | | | | | | | | | | $spreadsheet = new Spreadsheet(); | | $sheet = $spreadsheet->getActiveSheet(); | | | | | | | | $titCol = 'A'; | | foreach ($title as $key => $value) { | | | | $sheet->setCellValue($titCol . '1', $value); | | $titCol++; | | } | | $row = 2; | | foreach ($data as $item) { | | $dataCol = 'A'; | | foreach ($item as $value) { | | | | $sheet->setCellValue($dataCol . $row, $value); | | $dataCol++; | | } | | $row++; | | } | | | | ob_end_clean(); | | ob_start(); | | | | header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); | | header('Cache-Control: max-age=0'); | | | | header('Cache-Control: max-age=1'); | | | | | | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | | header('Cache-Control: cache, must-revalidate'); | | header('Pragma: public'); | | | | header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.date('YmdHis').'.xlsx"'); | | header("Content-Disposition:attachment;filename=".date('YmdHis').".xlsx"); | | | | $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); | | $writer->save('php://output'); | | | | | | $spreadsheet->disconnectWorksheets(); | | unset($spreadsheet); | | ob_end_flush(); | | return true; | | } |
|