public function phpexcel(){ //-----excel表导出
$dataid = $_GET['dataid'];
$status = $_GET['status'];
$Form = M('Form');
if($status == 1){
$field = array(
'goods','kfphone','phone','email','jylm',
'website','shname','zcdz','yyzznum','yyzzdateq',
'yyzzdatej','jynr','yyzzimg','type','idtype',
'idcard','idname','iddateq','iddatej','idcard1',
'idcard2','bankdetail','banknum','bankuser',
);
}else if($status ==2){
$field = array(
'wxnum','wxid','appid','jylm','goods',
'kfphone','phone','email','ztlb','trade',
'website','shname','zcdz','postalcode','type',
'idtype','idcard','idname','iddateq','iddatej',
'idcard1','idcard2','yyzznum','yyzzdateq','yyzzdatej',
'jynr','yyzzimg','dmz','dmzdateq','dmzdatej',
'dmzimg','bank','bankcity','bankdetail','banknum',
'bankuser','bankimg',
);
}
$res = $Form->field($field)->where("dataid = '$dataid'")->find();
vendor('phpexcel.Classes.PHPExcel'); //导入thinkphp第三方类库
$excel = new \PHPExcel(); //创建对象
//Excel表格式
$letter = array('A','B','C','D','E');
// 设置sheet的name
$excel->getActiveSheet()->setTitle('个体商户资料');
// 合并单元格
$excel->getActiveSheet()->mergeCells('A1:B1');
// 将A1单元格设置为加粗,居中
$styleArray1 = array(
'font' => array(
'bold' => true,
'size'=>12,
'color'=>array(
'argb' => '00000000',
),
),
'alignment' => array(
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
),
);
$excel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray1);
// 设置背景颜色
$excel->getActiveSheet()->getStyle('A2')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$excel->getActiveSheet()->getStyle('A2')->getFill()->getStartColor()->setARGB('006AD169');
$excel->getActiveSheet()->getStyle('B2')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
$excel->getActiveSheet()->getStyle('B2')->getFill()->getStartColor()->setARGB('006AD169');
// 设置宽width
$excel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
$excel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
//设置表头信息
if($status == 1){
$excel->getActiveSheet()->setCellValue("A1","微信支付商户资料表(个体工商户口)");
}else if($status == 2){
$excel->getActiveSheet()->setCellValue("A1","微信支付商户资料表");
}
$excel->getActiveSheet()->setCellValue("A2","项目");
$excel->getActiveSheet()->setCellValue("B2","内容");
// --------------------------------------------------
//表列数组
if($status == 1){
$tableleft = array(
'简述售卖的商品','商户客服电话','手机号码','重要邮箱','经营类目',
'公司网站','商户名称','注册地址','营业执照注册号','营业执照起始有效期',
'营业执照截止有效期','经营内容','营业执照扫描件','证件持有人类型','证件类型',
'证件号码','证件持有人姓名','证件起始有效期','证件截止有效期','证件正面扫描件',
'证件背面扫描件','开户银行详细名称','银行账户','开户人名称',
);
}else if($status == 2){
$tableleft = array(
'认证过的微信号','微信公众账号原始ID','APPID','经营范围','简述售卖的商品',
'商户客服电话','联系电话','重要邮箱','申请主体类别','行业类别',
'(可选填)公司网站','商家名称','注册地址','邮政编码','证件持有人类型',
'证件类型','证件号码','证件持有人姓名','证件起始有效期','证件截止有效期',
'证件正面扫描件','证件背面扫描件','营业执照注册号','营业执照起始有效期','营业执照截止有效期',
'经营内容','营业执照扫描件','组织机构代码','组织机构代码证起始有效期','组织机构代码证截止有效期',
'组织机构代码证扫描件','开户银行','开户银行省市信息','开户银行详细名称','银行账户',
'开户名称','银行账号证明函',
);
}
//填充表头信息
$n = 3;
for($i = 0;$i < count($tableleft);$i++) {
$excel->getActiveSheet()->setCellValue("A$n","$tableleft[$i]");
$n++;
}
//填充表格信息
$data = array();
foreach ($res as $value) {
$data[] = $value;
}
$j =3;
for ($i = 0;$i < count($data);$i++) {
$img = explode('.',$data[$i]);
if($img[1] == 'jpg' || $img[1] == 'gif' || $img == 'png' || $img == 'jpeg'){
// excel中插入图片
$objDrawing = new \PHPExcel_Worksheet_Drawing();
// $objDrawing->setName('Logo');
// $objDrawing->setDescription('Logo');
$objDrawing->setPath('Public/Home/images/mobileUpload/'.$data[$i]);
$objDrawing->setWidth(400);
$objDrawing->setHeight(123);
// 设置行高
$excel->getActiveSheet()->getRowDimension($j)->setRowHeight(123);
$objDrawing->setCoordinates('B'.$j);
$objDrawing->setWorksheet($excel->getActiveSheet());
}else{
$excel->getActiveSheet()->setCellValue("B$j",' '."$data[$i]");
}
$j++;
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel5($excel);
header("Pragma: public");
header("Expires: 0");
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");;
header('Content-Disposition:attachment;filename="'.$res['shname'].'商户申请.xls"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}