Exemple #1
0
 public function download()
 {
     $file = \Hnust\input('file');
     $download = new Download($this->uid);
     if (!$download->get($file)) {
         $this->code = Config::RETURN_ERROR;
         $this->msg = '未找到相关文件';
     }
 }
Exemple #2
0
 public function getExcel($uid, $sid, $term)
 {
     $data = $this->getSchdule($sid, $term);
     $objPHPExcel = new \PHPExcel();
     $objPHPExcel->setActiveSheetIndex(0);
     //默认样式
     $objPHPExcel->getActiveSheet()->setTitle('课表');
     $objPHPExcel->getDefaultStyle()->getFont()->setName('宋体');
     $objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
     $objPHPExcel->getDefaultStyle()->getAlignment()->setWrapText(true);
     $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
     $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $activeSheet = $objPHPExcel->getActiveSheet();
     //总长度及高度
     $excelWidth = 8;
     $excelHeight = 8;
     $allIndex = 'A1:' . \Hnust\num2alpha($excelWidth) . $excelHeight;
     //设置边框
     $activeSheet->getStyle($allIndex)->applyFromArray(array('borders' => array('allborders' => array('style' => \PHPExcel_Style_Border::BORDER_THIN))));
     //设置行宽
     $activeSheet->getColumnDimension('A')->setWidth(10);
     for ($i = 2; $i <= $excelWidth; $i++) {
         $activeSheet->getColumnDimension(\Hnust\num2alpha($i))->setWidth(20);
     }
     //设置行高
     $activeSheet->getRowDimension('1')->setRowHeight(30);
     for ($i = 3; $i <= $excelHeight - 1; $i++) {
         $activeSheet->getRowDimension($i)->setRowHeight(80);
     }
     $headline = "湖南科技大学 {$term} 学年学期 {$sid} 个人课表";
     $week = array('', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日');
     $periods = array('', '第一二节', '第三四节', '第五六节', '第七八节', '第九十节');
     //填充大小标题
     $activeSheet->setCellValue('A1', $headline);
     $activeSheet->getStyle('A1')->getFont()->setBold(true);
     $activeSheet->getStyle('A1')->getFont()->setSize(16);
     $activeSheet->mergeCells('A1:' . \Hnust\num2alpha($excelWidth) . '1');
     //填充课表
     for ($i = 1; $i <= $excelWidth; $i++) {
         for ($j = 2; $j <= $excelHeight - 1; $j++) {
             $excelIndex = \Hnust\num2alpha($i) . $j;
             //第几节课
             if ($i == 1) {
                 $activeSheet->setCellValue($excelIndex, $periods[$j - 2]);
                 $activeSheet->getStyle($excelIndex)->getFont()->setBold(true);
                 //星期几
             } else {
                 if ($j == 2) {
                     $activeSheet->setCellValue($excelIndex, $week[$i - 1]);
                     $activeSheet->getStyle($excelIndex)->getFont()->setBold(true);
                     //上什么课
                 } else {
                     $cellValue = '';
                     $courses = $data[$i - 1][$j - 2];
                     foreach ($courses as $course) {
                         $cellValue .= "{$course['course']}\n{$course['teacher']}\n{$course['time']} {$course['classroom']}";
                         if ($course != end($courses)) {
                             $cellValue .= "\n---------------\n";
                         }
                     }
                     $activeSheet->setCellValue($excelIndex, $cellValue);
                     $activeSheet->getStyle($excelIndex)->getFont()->setSize(9);
                 }
             }
         }
     }
     //备注
     $remarks = '备注:' . $data['remarks'] . '; By:Tick网络工作室';
     $markIndex = 'A' . $excelHeight;
     $marksIndex = $markIndex . ':' . \Hnust\num2alpha($excelWidth) . $excelHeight;
     $activeSheet->setCellValue($markIndex, $remarks);
     $activeSheet->getStyle($markIndex)->getFont()->setSize(8);
     $activeSheet->mergeCells($marksIndex);
     //缓存与下载
     $download = new Download($uid);
     $fileName = $headline . $term . '.xls';
     $fileInfo = $download->set($fileName);
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save($fileInfo['path']);
     $download->rewrite($fileInfo['rand']);
 }
Exemple #3
0
 public function getExcel($uid, $term, $scope, $by)
 {
     //获取排名情况
     $rank = $this->getRank($term, $scope, $by);
     $objPHPExcel = new \PHPExcel();
     $objPHPExcel->setActiveSheetIndex(0);
     //默认样式
     $objPHPExcel->getActiveSheet()->setTitle($this->title);
     $objPHPExcel->getDefaultStyle()->getFont()->setName('宋体');
     $objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
     $objPHPExcel->getDefaultStyle()->getAlignment()->setWrapText(true);
     $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
     $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $activeSheet = $objPHPExcel->getActiveSheet();
     //总长度及高度
     $excelWidth = count($this->courses) + 10;
     $excelHeight = count($rank) + 2;
     $allIndex = 'A1:' . \Hnust\num2alpha($excelWidth) . $excelHeight;
     //设置边框
     $activeSheet->getStyle($allIndex)->applyFromArray(array('borders' => array('allborders' => array('style' => \PHPExcel_Style_Border::BORDER_THIN))));
     //第一行
     $col = array_merge(array('序号', '姓名', '学号'), $this->courses, array('科目数', '不及格门数', '平均分', '总分', '所得学分', '平均学分绩', '平均学分绩点'));
     for ($i = 0; $i < count($col); $i++) {
         $excelIndex = \Hnust\num2alpha($i + 1) . '1';
         $activeSheet->setCellValue($excelIndex, $col[$i]);
         $activeSheet->getStyle($excelIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('00C5CFCA');
         $activeSheet->getColumnDimension('B')->setWidth(10);
         if ($i != 0 && $i != 1) {
             $activeSheet->getColumnDimension(\Hnust\num2alpha($i + 1))->setWidth(15);
         }
     }
     $activeSheet->getRowDimension('1')->setRowHeight(25);
     $activeSheet->freezePane('A2');
     //输出所有成绩
     for ($i = 0; $i < count($rank); $i++) {
         $col = array_merge(array($i + 1, $rank[$i]['name'], $rank[$i]['sid']), $rank[$i]['course'], array(count($rank[$i]['course']), $rank[$i]['countFail'], $rank[$i]['avgMark'], $rank[$i]['countMark'], $rank[$i]['countCredit'], $rank[$i]['avgGpa'], $rank[$i]['avgPoint']));
         for ($j = 0; $j < count($col); $j++) {
             $excelIndex = \Hnust\num2alpha($j + 1) . ($i + 2);
             $activeSheet->setCellValue($excelIndex, $col[$j]);
             //单双行背景
             if ($i % 2 == 0) {
                 $activeSheet->getStyle($excelIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('00eeeeee');
             }
             if ($j > 2 && $j < count($rank[$i]['course']) + 3) {
                 if (is_numeric($col[$j]) && $col[$j] < 60 || $col[$j] == '不及格') {
                     $activeSheet->getStyle($excelIndex)->getFont()->getColor()->setARGB(\PHPExcel_Style_Color::COLOR_RED);
                 }
             }
         }
     }
     //备注
     $markIndex = 'A' . $excelHeight;
     $marksIndex = $markIndex . ':' . \Hnust\num2alpha($excelWidth) . $excelHeight;
     $content = '    注:此排名为第三方统计,不代表学校最后统计结果;此统计仅供参考。By:Tick网络工作室';
     $activeSheet->setCellValue($markIndex, $content);
     $activeSheet->mergeCells($marksIndex);
     $activeSheet->getStyle($marksIndex)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
     //缓存与下载
     $download = new Download($uid);
     $fileName = $this->title . '.xls';
     $fileInfo = $download->set($fileName);
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save($fileInfo['path']);
     $download->rewrite($fileInfo['rand']);
 }