public function email_daochu(){
//导出Excel
$xlsName = "邮寄人员基本信息".date('Y-m-d',time());
$xlsCell = array(
array('centercode', '行政区划'),
array('', '个人编号'),
array('card_num', '身份证号码'),
array('name', '姓名'),
array('sex', '性别'),
array('nation', '民族'),
array('birthday', '出生日期'),
);
$where['step_status'] = 9; //采集完成
$where['examine_status'] = 1; //审核通过
$where['is_mail'] = 1; //代表邮寄
$xlsModel = M('wx_archives');
$xlsData = $xlsModel->where($where)->select();
// var_dump($xlsData);die;
if (empty($xlsData)) {
$this->error('暂时没有符合导出条件的数据!');
}
foreach ($xlsData as $k => $v) {
$map['unitname'] = $v['company'];
$unit_data = M('unitinfo_shi')->where($map)->find();
$xlsData[$k]['centercode'] = $unit_data['centercode']; //行政区划
$xlsData[$k]['unitcode'] = $unit_data['unitcode']; //单位编号
$xlsData[$k]['card_num'] = $v['card_num']; //身份证号码
$xlsData[$k]['phone'] = $v['phone']; //联系电话
$xlsData[$k]['source'] = '99'; //数据来源
$communication_address = str_replace('/', '', $v['communication_address']);
}
$this->email_exportExcel($xlsName, $xlsCell, $xlsData,$personid);
}
public function email_exportExcel($expTitle, $expCellName, $expTableData,$personid){
$xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
$fileName = $xlsTitle;
// $fileName = $_SESSION['account'] . date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
$cellNum = count($expCellName);
$dataNum = count($expTableData);
vendor("PHPExcel.PHPExcel");
$objPHPExcel = 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');
// $objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(13);
$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(13);
$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('AB')->setWidth(22);
$objPHPExcel->getActiveSheet()->getColumnDimension('AC')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('AD')->setWidth(13);
for ($i = 0; $i < $cellNum; $i++) {
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '1', $expCellName[$i][1]);
}
// Miscellaneous glyphs, UTF-8
for ($i = 0; $i < $dataNum; $i++) {
for ($j = 0; $j < $cellNum; $j++) {
$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]]);
$objPHPExcel->getActiveSheet(0)->setCellValueExplicit($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]],\PHPExcel_Cell_DataType::TYPE_STRING);
}
}
$path = $_SERVER['DOCUMENT_ROOT']."/Infomation_upload/email_info/".$fileName.".xls";
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($path);
if (!file_exists($path)) {
header("Content-type: text/html; charset=utf-8");
$this->error("文件未找到!");
exit;
} else {
header("Cache-Control: max-age=0");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename=' . basename($path)); // 文件名
header("Content-Type: application/zip"); // zip格式的
header("Content-Transfer-Encoding: binary"); // 告诉浏览器,这是二进制文件
header('Content-Length:' . filesize($path)); // 告诉浏览器,文件大小
@readfile($path);//输出文件;
}
}