[PHP]代码
set_time_limit(0);//防止数据量过大超时 //处理进程 import('ORG.Net.UploadFile'); $upload = new UploadFile(); // 实例化上传类 $upload->maxSize = 4 * 1024 * 1024; // 设置附件上传大小 $upload->allowExts = array('xls'); $upload->savePath = './Upload/data/'; // 设置附件上传目录 $upload->saveRule = date('YmdHis'); if (!$upload->upload()) { // 上传错误提示错误信息 echo $upload->getErrorMsg(); } else { //进行异常捕获,防止导入错误 try{ //导入完成,开始数据处理流程 $info = $upload->getUploadFileInfo(); $data = $info[0]; $path = $data['savepath'].$data['savename']; /** * 开始Excel处理进程 */ vendor('PHPExcel.PHPExcel'); $objReader = new PHPExcel_Reader_Excel5(); $objExcel = $objReader->load($path); $objSheet = $objExcel->getActiveSheet(); $rows = $objSheet->getHighestRow();//行数 /** * 单元格定义 * B 二级学科代码 * C 二级学科名称 * D 一级学科代码 * E 一级学科名称 * F 学院代码 * G 学院名称 */ //定义数组 $second_discipline_code = array(); $second_discipline_name = array(); $first_discipline_code = array(); $first_discipline_name = array(); $college_code = array(); $college_name = array(); for($i=1;$i<=$rows;$i++){ $second_discipline_code[] = $objSheet->getCell("B$i")->getFormattedValue(); $second_discipline_name[] = $objSheet->getCell("C$i")->getFormattedValue(); $first_discipline_code[] = $objSheet->getCell("D$i")->getFormattedValue(); $first_discipline_name[] = $objSheet->getCell("E$i")->getFormattedValue(); $college_code[] = $objSheet->getCell("F$i")->getFormattedValue(); $college_name[] = $objSheet->getCell("G$i")->getFormattedValue(); } //写入数据库 $firstDataMdl = M('DataFirstDiscipline'); $secondDataMdl = M('DataSecondDiscipline'); $first_discipline_code_backup = $first_discipline_code;//不去重复的备份 $first_discipline_code = array_unique($first_discipline_code);//去重 //一级学科导入 foreach($first_discipline_code as $k=>$v){ $temp['college_id'] = $college_code[$k]; $temp['first_discipline_code'] = $v; $temp['first_discipline_name'] = $first_discipline_name[$k]; $firstDataMdl->add($temp); } //二级学科导入 foreach($second_discipline_code as $k=>$v){ $temp['second_discipline_code'] = $v; $temp['second_discipline_name'] = $second_discipline_name[$k]; //根据一级学科代码查一级学科ID $first_discipline_code_flag = $first_discipline_code_backup[$k]; $id = $firstDataMdl->where("first_discipline_code = %d",$first_discipline_code_flag)->getField('first_discipline_id'); $temp['first_discipline_id'] = $id; $secondDataMdl->add($temp); } echo '导入成功完成!'; }catch (PHPExcel_Exception $e){ echo $e->getMessage(); }catch (ThinkException $e){ echo $e->getMessage(); }catch (Exception $e){ echo '程序异常,导入失败!'; } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)
