业务需求与Ai电话对接,只可以上传xlsx格式表格
醉了
/**
* @description 用户数据导出
* @author Angus
*/
public function ExportMember(){
$Data = I('get.');
$Num = empty($Data['num'])?800:$Data['num'];
$Time = $Data['time'];
$Media = '4,123,131,118,133';
$Limit = $Num+100;
$Firm = '腾讯';
$Comment = '暂无';
$EndTime = '';
$MemberList = M('Member') ->field('phone, addtime') ->where(array('addtime'=>array('gt', $Time), 'id_card'=>array('neq', ''))) ->order('addtime asc') ->limit($Limit) ->select();
$PhoneList = array();
foreach($MemberList as $k => $v){
$PhoneList[$v['phone']] = $v['phone'];
if(count($PhoneList) == $Num){
$EndTime = $v['addtime']+1;
break;
}
}
$List = array();
foreach($PhoneList as $v){
$List[] = array(
'Firm'=>'',
'UserName'=>'',
'UserPhone'=>$v,
'Comment'=>'',
);
}
$Header = array('企业','姓名','电话','备注');
$Keys = array('Firm','UserName','UserPhone','Comment');
$FileName = '数据报表(截止时间:'.date('YmdHis', $EndTime).')';
$this ->exportExcel($Header, $List, $FileName, './', false);
}
/**
* 数据导出
* @param array $title 标题行名称
* @param array $data 导出数据
* @param string $fileName 文件名
* @param string $savePath 保存路径
* @param $type 是否下载 false--保存 true--下载
* @return string 返回文件全路径
* @throws PHPExcel_Exception
* @throws PHPExcel_Reader_Exception
*/
function exportExcel($title=array(), $data=array(), $fileName='', $savePath='./', $isDown=false){
vendor("PHPExcel.PHPExcel.Classes.PHPExcel");
$obj = new \PHPExcel();
//横向单元格标识
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
$obj->getActiveSheet(0)->setTitle('sheet名称'); //设置sheet名称
$_row = 1; //设置纵向单元格标识
if($title){
$i = 0;
foreach($title AS $v){ //设置列标题
$obj->setActiveSheetIndex(0)->setCellValue($cellName[$i].$_row, $v);
$i++;
}
$_row++;
}
//填写数据
if($data){
$i = 0;
foreach($data AS $_v){
$j = 0;
foreach($_v AS $_cell){
$obj->getActiveSheet(0)->setCellValue($cellName[$j] . ($i+$_row), $_cell);
$j++;
}
$i++;
}
}
//文件名处理
if(!$fileName){
$fileName = uniqid(time(),true);
}
$objWrite = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
if($isDown){ //网页下载
header('pragma:public');
header("Content-Disposition:attachment;filename=$fileName.xls");
$objWrite->save('php://output');exit;
}
$_fileName = iconv("utf-8", "gb2312", $fileName); //转码
header('pragma:public');
header("Content-Disposition:attachment;filename=$_fileName.xlsx");
$objWrite->save('php://output');exit;
return $savePath.$fileName.'.xlsx';
}