标签:trim .sh 缓冲 cat encode each fun ++ logic
/** * excel下载。单个职位下的求职者 */ public function test() { $deliveryIds = trim($this->_param[‘deliveryIds‘], ‘,‘); if(empty($deliveryIds)){ return json($this->_format_return_data([], FAILED, ‘参数不对‘)); } //取该职位下的用户 $res = $this->delivery_logic->getExcelList($deliveryIds); if (empty($res)) { return json($this->_format_return_data([], FAILED, ‘参数不对‘)); } foreach ($res as &$val) { //计算年龄 $val[‘age‘] = $this->getAge(strtotime($val[‘birthDay‘])); $val[‘sex‘] = !empty($val[‘sex‘])?config(‘status.sex‘)[$val[‘sex‘]]:‘‘; $val[‘education‘] = !empty($val[‘education‘])?config(‘status.education‘)[$val[‘education‘]]:‘‘; $val[‘jobType‘] = !empty($val[‘jobType‘])?config(‘status.‘)[$val[‘jobType‘]]:‘‘; $val[‘trace‘] = !empty($val[‘trace‘])?config(‘status.trace‘)[$val[‘trace‘]]:‘‘; $val[‘yearSalary‘] = !empty($val[‘yearSalary‘])?config(‘status.hopeSalary‘)[$val[‘yearSalary‘]]:‘‘; } //引入核心文件 vendor("Util.PHPExcel"); $objPHPExcel = new \PHPExcel(); $objPHPExcel->getProperties()->setCreator(‘http://www.jb51.net‘) ->setLastModifiedBy(‘http://www.jb51.net‘) ->setTitle(‘Office 2007 XLSX Document‘) ->setSubject(‘Office 2007 XLSX Document‘) ->setDescription(‘Document for Office 2007 XLSX, generated using PHP classes.‘) ->setKeywords(‘office 2007 openxml php‘) ->setCategory(‘Result file‘); $objPHPExcel->getActiveSheet()->getStyle(‘A1:S1‘)->getFont()->setBold(true); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue(‘A1‘, ‘姓名‘) ->setCellValue(‘B1‘, ‘性别‘) ->setCellValue(‘C1‘, ‘年龄‘) ->setCellValue(‘D1‘, ‘学历‘) ->setCellValue(‘E1‘, ‘申请时间‘) ->setCellValue(‘F1‘, ‘简历进度‘) ->setCellValue(‘G1‘, ‘工作年限‘) ->setCellValue(‘H1‘, ‘工作类型‘) ->setCellValue(‘I1‘, ‘期望薪资‘); $i = 2; foreach ($res as $v) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue(‘A‘ . $i, $v[‘name‘]) ->setCellValue(‘B‘ . $i, $v[‘sex‘]) ->setCellValue(‘C‘ . $i, $v[‘age‘]) ->setCellValue(‘D‘ . $i, $v[‘education‘]) ->setCellValue(‘E‘ . $i, $v[‘deliveryTime‘]) ->setCellValue(‘F‘ . $i, $v[‘trace‘]) ->setCellValue(‘G‘ . $i, $v[‘workExp‘]) ->setCellValue(‘H‘ . $i, $v[‘jobType‘]) ->setCellValue(‘I‘ . $i, $v[‘yearSalary‘]); $i++; } $objPHPExcel->getActiveSheet()->setTitle(‘商城会员信息‘); $objPHPExcel->setActiveSheetIndex(0); $filename = urlencode(‘申请者列表‘) . ‘_‘ . date(‘Y-m-dHis‘); //*生成xlsx文件 /* ob_end_clean();//清除缓冲区,避免乱码 header(‘Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet‘); header(‘Content-Disposition: attachment;filename="‘.$filename.‘.xlsx"‘); header(‘Cache-Control: max-age=0‘); $objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,‘Excel2007‘); */ /* 生成xls文件 */ ob_end_clean(); //清除缓冲区,避免乱码 header(‘Content-Type: application/vnd.ms-excel;charset=utf-8‘); header("Content-Disposition:attachment;filename=test_data.xls"); header(‘Content-Disposition: attachment;filename="‘ . $filename . ‘.xls"‘); header(‘Cache-Control: max-age=0‘); vendor("Util.PHPExcel"); $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel5‘); //$objWriter->save($filename); $objWriter->save(‘php://output‘); }
标签:trim .sh 缓冲 cat encode each fun ++ logic
原文地址:https://www.cnblogs.com/xin-jun/p/9353895.html