Ejemplo n.º 1
0
 public function actionOutExcel()
 {
     $start = isset($_GET['start']) ? $_GET['start'] : date("Y-m-d");
     $end = isset($_GET['end']) ? $_GET['end'] : date("Y-m-d");
     $name = isset($_GET['name']) ? $_GET['name'] : '';
     $type = isset($_GET['type']) ? $_GET['type'] : '';
     $page = isset($_GET['page']) ? $_GET['page'] : 1;
     $where = '';
     $whereArray = array(':start' => $start . ' 00:00:00', ':end' => $end . ' 23:59:59');
     if (!empty($name)) {
         $where .= ' and title like :name';
         $whereArray[':name'] = $name . '%';
     }
     $tongji = new TongjiData();
     $criteria = new CDbCriteria();
     $criteria->condition = 'searchtime >= :start and searchtime <= :end' . $where;
     $criteria->params = $whereArray;
     if (!empty($type)) {
         $typeIds = TongjiType::model()->getTypeIdsByPid($type);
         $criteria->addInCondition("type_id", $typeIds);
     }
     $criteria->order = 'type_id,id';
     $criteria->offset = ($page - 1) * 40;
     $criteria->limit = 40;
     $datas = $tongji->findAll($criteria);
     ob_end_clean();
     ob_start();
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file");
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'ID')->setCellValue('B1', '名称')->setCellValue('C1', '平台渠道')->setCellValue('D1', '排名')->setCellValue('E1', '采集时间');
     if (!empty($datas)) {
         $i = 2;
         foreach ($datas as $v) {
             $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$i}", $v['id'])->setCellValue("B{$i}", $v['title'])->setCellValue("C{$i}", $v->types->type)->setCellValue("D{$i}", $v['ranking'])->setCellValue("E{$i}", $v['searchtime']);
             $i++;
         }
     }
     $objPHPExcel->getActiveSheet()->setTitle('采集数据');
     $objPHPExcel->setActiveSheetIndex(0);
     $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
     header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
     header("Content-Type:application/force-download");
     header("Content-Type:application/vnd.ms-execl");
     header("Content-Type:application/octet-stream");
     header("Content-Type:application/download");
     $fireName = date("YmdHis") . '数据导出';
     header("Content-Disposition:attachment;filename={$fireName}.xls");
     header("Content-Transfer-Encoding:binary");
     $objWriter->save("php://output");
     Yii::app()->end();
     spl_autoload_register(array('YiiBase', 'autoload'));
 }
Ejemplo n.º 2
0
 public function actionIndex()
 {
     $types = TongjiType::model()->findAll();
     $updateTime = date("Y-m-d H:i:s");
     foreach ($types as $type) {
         switch ($type['pid']) {
             case 1:
                 if ($this->_saveXYData($type)) {
                     TongjiType::model()->updateCrawlTime($type['id'], $updateTime);
                 }
                 break;
             case 4:
                 $this->_saveAishiData($type);
                 TongjiType::model()->updateCrawlTime($type['id'], $updateTime);
                 break;
             case 7:
                 $this->_saveItoolsData($type);
                 TongjiType::model()->updateCrawlTime($type['id'], $updateTime);
                 break;
             case 16:
                 $this->_saveHMData($type);
                 TongjiType::model()->updateCrawlTime($type['id'], $updateTime);
                 break;
             case 35:
                 $this->_saveKYData($type);
                 TongjiType::model()->updateCrawlTime($type['id'], $updateTime);
                 break;
             case 171:
                 $this->_saveFNData($type);
                 TongjiType::model()->updateCrawlTime($type['id'], $updateTime);
                 break;
             default:
                 break;
         }
     }
 }