thinkphp 访问此控制方法就可以导入了
百度网盘依赖文件下载:
链接:https://pan.baidu.com/s/1L8HBtDtiBisAikQKbRnZIg
提取码:cjje
复制这段内容后打开百度网盘手机App,操作更方便哦
//数据导入
public function impUser(){ if (!empty($_FILES)) { $upload = new \Think\Upload();// 实例化上传类
$upload->exts = array('xlsx','xls');
$upload->rootPath = './Uploads/';
$upload->savePath = '/excel/'; // 设置附件上传(子)目录 $info = $upload->upload();
if (!$info) {
$this->error($upload->getError());
} $file_name='./Uploads'.$info['daoru_data']['savepath'].$info['daoru_data']['savename']; vendor("PHPExcel.PHPExcel");
$objReader = \PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load($file_name,$encode='utf-8');
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数
// dump($objPHPExcel->getActiveSheet()->getCell("A2")->getValue());die();
for($i=2;$i<=$highestRow;$i++)
{
$data['name'] = $objPHPExcel->getActiveSheet()->getCell("A".$i)->getValue();
$data['xingbie'] = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
$data['birth'] = $objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();
$data['minzu'] = $objPHPExcel->getActiveSheet()->getCell("D".$i)->getValue();
$data['jiguan'] = $objPHPExcel->getActiveSheet()->getCell("E".$i)->getValue();
$data['cj_time'] = $objPHPExcel->getActiveSheet()->getCell("F".$i)->getValue();
$data['rd_time'] = $objPHPExcel->getActiveSheet()->getCell("G".$i)->getValue();
$data['birth_di'] = $objPHPExcel->getActiveSheet()->getCell("H".$i)->getValue();
$data['ys_xueli'] = $objPHPExcel->getActiveSheet()->getCell("I".$i)->getValue();
$data['zg_xueli'] = $objPHPExcel->getActiveSheet()->getCell("J".$i)->getValue();
$data['gz_danwei'] = $objPHPExcel->getActiveSheet()->getCell("K".$i)->getValue();
$data['zhiwu'] = $objPHPExcel->getActiveSheet()->getCell("L".$i)->getValue();
$data['sz_zhidui'] = $objPHPExcel->getActiveSheet()->getCell("M".$i)->getValue();
$data['dn_zhiwu'] = $objPHPExcel->getActiveSheet()->getCell("N".$i)->getValue();
$data['jianli'] = $objPHPExcel->getActiveSheet()->getCell("O".$i)->getValue();
$data['abc_id'] = I('abc_id');
$data['d_id'] = I('d_id');
$data['time'] = time(); $tmp1['chengwei'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("P".$i)->getValue());
$tmp1['jname'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("Q".$i)->getValue());
$tmp1['nianyue'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("R".$i)->getValue());
$tmp1['zhengzhi'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("S".$i)->getValue());
$tmp1['gongzuo'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("T".$i)->getValue());
// dump($tmp1);
// 这些注释的是错误的
//// $tmp1 = explode("\r\n", $tmp1);
// $tmp['chengwei'] = json_encode($tmp1);
// $tmp['jname'] = json_encode($tmp1);
// $tmp['nianyue'] = json_encode($tmp1);
// $tmp['zhengzhi'] = json_encode($tmp1);
// $tmp['gongzuo'] = json_encode($tmp1); $tmp2['ry_tiem'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("U".$i)->getValue());
$tmp2['ry_chenghao'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("V".$i)->getValue());
$tmp2['ry_shoujiang'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("W".$i)->getValue());
$tmp2['ry_wenjian'] = explode("\r\n", $objPHPExcel->getActiveSheet()->getCell("X".$i)->getValue());
//这些注释的是错误的,
// $tmp3 = explode("\r\n", $tmp2);
// $tmp_ry['ry_tiem'] = json_encode($tmp2);这种格式是错的
// $tmp_ry['ry_chenghao'] = json_encode($tmp2);
// $tmp_ry['ry_shoujiang'] = json_encode($tmp2);
// $tmp_ry['ry_wenjian'] = json_encode($tmp2); $data['jiating'] = json_encode($tmp1);
$data['rongyu'] = json_encode($tmp2);
// str_replace('[\','[',$jiating);
dump($data['jiating']);die();
$re = M('linzi_user') -> add($data);
}
$this->success('导入成功!');
}else
{
$this->error("请选择上传的文件");
}
// dump($_FILES);die(); }