public function fakeExcel() {
#接值
$adid = I('get.adid');
$appid = I('get.appid');
#用adid和appid俩个查询条件去查询今天的导入数据,进行导出
$data = M('ApiCheckFake')->where(array('adid'=>$adid,'appid'=>$appid,'addTime'=>date('Y-m-d',time())))->select();
$channelName = $this->getchannelName($data[0]['appid']);
Vendor('PHPExcel');
$objPHPExcel = new \PHPExcel();
$name = '起点互动_'.$channelName['name'].$data[0]['add_time'].'-'.$data[0]['act_time'];
#以下就是对处理Excel里的数据, 横着取数据,主要是这一步,其他基本都不要改
#设置第一行标题
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'IDFA');
$objPHPExcel->getActiveSheet()->setCellValue('B1', '开始时间');
$objPHPExcel->getActiveSheet()->setCellValue('C1', '激活时间');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'UDID');
$objPHPExcel->getActiveSheet()->setCellValue('E1', '机型');
$objPHPExcel->getActiveSheet()->setCellValue('F1', '系统');
$objPHPExcel->getActiveSheet()->setCellValue('G1', 'IP');
$objPHPExcel->getActiveSheet()->setCellValue('H1', '关键词');
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
foreach($data as $k => $v){
#从第二行开始写入数据 第一行是标题
$num=$k+2;
#Excel的第A列,uid是你查出数组的键值,下面以此类推
$objPHPExcel ->setActiveSheetIndex(0)
->setCellValue('A'.$num, $v['idfa'])
->setCellValue('B'.$num, date('Y-m-d H:i:s',$v['add_time']))
->setCellValue('C'.$num, date('Y-m-d H:i:s',$v['act_time']))
->setCellValue('D'.$num, $v['udid'])
->setCellValue('E'.$num, $v['model'])
->setCellValue('F'.$num, $v['os'])
->setCellValue('G'.$num, $v['ip'])
->setCellValue('H'.$num, $v['keyword'])
;
}
$objPHPExcel->getActiveSheet()->setTitle('User');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: applicationnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$name.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}