diff --git a/application/rongyu/common.php b/application/rongyu/common.php index b3d9bbc7..a8143662 100644 --- a/application/rongyu/common.php +++ b/application/rongyu/common.php @@ -1 +1 @@ -field('id,rongyuce,title,bianhao,hjschool,subject,jiangxiang,hjshijian,pic') + ->with([ + 'hjJsry'=>function($query){ + $query->field('rongyuid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + 'cyJsry'=>function($query){ + $query->field('rongyuid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + 'ryTuce'=>function($query){ + $query->field('id,title,fzshijian'); + } + ]) + ->select(); + + + if($list->isEmpty()) + { + $this->error('兄弟,没有要下载的信息呀~'); + return ''; + } + + + //通过工厂模式创建内容 $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('jsRongyu.xlsx'); - $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->getCell('A1')->setValue('John'); - $worksheet->getCell('A2')->setValue('Smith'); + $worksheet->getCell('A1')->setValue($list[0]['ryTuce']['title']); + // 循环为excel每行赋值 + foreach ($list as $key => $value) { + $worksheet->getCell('A'.($key+3))->setValue($key+1); + $worksheet->getCell('B'.($key+3))->setValue($value->title); + $worksheet->getCell('C'.($key+3))->setValue($value->title); + $worksheet->getCell('D'.($key+3))->setValue($value->title); + $worksheet->getCell('E'.($key+3))->setValue($value->title); + $worksheet->getCell('F'.($key+3))->setValue($value->title); + $worksheet->getCell('G'.($key+3))->setValue($value->title); + $worksheet->getCell('H'.($key+3))->setValue($value->title); + } + $worksheet->getCell('A2'); //通过工厂模式来写内容 - $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); - $writer->save('write.xls');; + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename="' . $list[0]['ryTuce']['title'] . '.xlsx"'); + header('Cache-Control: max-age=0'); + $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); + $writer->save('php://output'); + + $spreadsheet->disconnectWorksheets(); + unset($spreadsheet); + return ''; } } diff --git a/public/jsRongyu.xlsx b/public/jsRongyu.xlsx index ccb3b7de..daed87e4 100644 Binary files a/public/jsRongyu.xlsx and b/public/jsRongyu.xlsx differ diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index eb053628..00000000 --- a/public/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: diff --git a/public/write.xls b/public/write.xls deleted file mode 100644 index 2363cf6f..00000000 Binary files a/public/write.xls and /dev/null differ