『Dcat Admin』如何获取$grid中的数据?
使用第三方包 PhpSpreadsheet 导出excel
导出方法如下
public static function unitExport($data = null) { $file = public_path().'\static\excel\unit_export_template_001.xlsx'; $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file); $worksheet = $spreadsheet->getActiveSheet(); // data = [[],[],[],[]] // 设置数据 // foreach ($data as $item){ // // } $worksheet->getCell('A4')->setValue('John'); $worksheet->getCell('A5')->setValue('Smith'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="'.'基础数据清单-'.Date('Ymd-His').'.xls'.'"'); header('Cache-Control: max-age=0'); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); $writer->save('php://output'); }
我需要Grid中的数据传入方法,但是没办法获取所有或某页的数据
推荐文章: