/**
* 导入Excel功能   是把execl表中的数据添加到数据表中
*/
public function import(){
if (!empty($_FILES)) {
$file = request()->file('import');
$info = $file->rule('uniqid')->move(ROOT_PATH . 'public' . DS . 'suffix');//移动到public/suffix下

if($info){
$file_name = './public/suffix/'.$info->getFilename();
}else{
// 上传失败获取错误信息
echo $file->getError();
}

Vendor('PHPExcel.PHPExcel');
Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
// 读取Excel文件内容
$PHPReader = new \PHPExcel_Reader_Excel2007();
$PHPExcel = $PHPReader->load($file_name);
$currentSheet = $PHPExcel->getSheet(0); //读取excel文件中的第一个工作表
$allColumn = $currentSheet->getHighestColumn(); //取得最大的列号
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
$arr = array(); //声明数组
/**从第二行开始输出,因为excel表中第一行为列名*/
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){

/**从第A列开始输出*/
for($currentColumn= 'A';$currentColumn<= $allColumn; $currentColumn++){

//数据坐标
$address = $currentColumn . $currentRow;
//读取到的数据,保存到数组$data中
$data[$currentRow][$currentColumn] = $currentSheet->getCell($address)->getValue();
/**如果输出汉字有乱码,则需将输出内容用iconv函数进行编码转换,如下将gb2312编码转为utf-8编码输出*/
//echo iconv('utf-8','gb2312', $val)."\t";
}
}
foreach ($data as $k => $v) {
$where = ['suffix'=>$v['A']];
$num = Db('suffix')->where($where)->value('id');
if(!$num){
$arr['suffix'] = $v['A'];
$arr['companyname'] = $v['B'];
$num = Db('suffix')->insert(['suffix'=>$arr['suffix'],'companyname'=>$arr['companyname'],'creat_time'=>date('y-m-d h:i:s')]);
if($num < 0){
return $this->error('导入数据库失败');
}
}
}

return $this->success('导入成功');

}

execl 导入的更多相关文章

  1. MVC execl 导入导出

    MVC execl 导入导出 <input id="xls" name="xls" type="file" style="w ...

  2. NET 5 Execl导入数据处理(EppLus、NPOI)

    先来简单介绍下市面上最广泛常见的三种操作excel库的优缺点1.NPOI 优点:免费开源,无需装Office即可操作excel, 支持处理的文件格式包括xls, xlsx, docx.格式 缺点:不支 ...

  3. Execl导入问题之文本转换

    前些天在基础数据的导入过程中,遇到了这样一个问题:数据明明存在,可是就是不识别!给出的错误提示是:该数据对应的外键不存在! 我找出其中的一条数据,在外键表中查询是存在的!问题出在哪里了呢? 从exec ...

  4. POI事件模型处理execl导入功能(只支持07版本的execl)

    由于通过new XSSFWorkbook 这种方式导入导致生产环境端口宕机.通过dump文件和javacore文件分析是导入功能导致的.解决办法:自己通过网上写的工具类,不知道是否存在bug. pac ...

  5. Execl导入系统

    文件导入功能 前台代码: Content\JS\jquery.ajaxfileupload.js<script src="~/Content/JS/jquery.ajaxfileupl ...

  6. 2020-06-30 pol实现execl导入导出

    1.导入依赖 <!-- 解析表格 --> <dependency> <groupId>org.apache.poi</groupId> <arti ...

  7. 基于NPOI的Execl导入导出例子

    源地址:http://bbs.csdn.net/topics/390830774

  8. 利用NPOI导出数据到Execl

    相信很多童鞋都开发过Execl的导入导出功能,最近产品中无论是后台数据分析的需要,还是前端满足用户管理的方便,都有Execl导入导出的维护需求产生. 以前做这个功能,如果是web,利用HttpCont ...

  9. PHP Yii2.0PHPexecl导入。

    use app\models\execl; use \PHPExcel; /*execl导入数据*/ public function Execlupload(){ if(Yii::$app->r ...

随机推荐

  1. Android.Study.Question

    1. NullPointerException 1.1 发生该异常的原因. 1.2 解决方法有哪几种? try-catch 2. Eclipse 中 debug/run 两个模式,run 是relea ...

  2. 在nginx中,禁止IP访问.只可以使用域名访问.

    if ($host ~* "\d+\.\d+\.\d+\.\d+"){ ; } 其实说白了, 就是进行host主机头过滤,使用正则来判断下.

  3. Pairs of Songs With Total Durations Divisible by 60 LT1010

    In a list of songs, the i-th song has a duration of time[i] seconds. Return the number of pairs of s ...

  4. spring4.3.9 @ResponseBody中文乱码,全是问号

    <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> < ...

  5. maven打包之后为什么class文件中没有注释了?

    <!--生成doc jar包--> <plugin> <groupId>org.apache.maven.plugins</groupId> <a ...

  6. android源码下载/查看地址

    源码下载: http://git.omapzoom.org/ 高通平台android源码下载地址: https://www.codeaurora.org/xwiki/bin/QAEP/WebHome ...

  7. SQL 获得两个时间段之间的数据

    一般保存在数据库中的日期精度很高,比如'2014-04-15 16:31:22.000' 而一般用户选择的时间精度是精确到日的,比如'2012-04-15' 所以你想取出两个日期之间的数据,如果用下面 ...

  8. Java学习笔记:注解Annotation

    annotation的概念 In the Java computer programming language, an annotation is a form of syntactic metada ...

  9. gcc -ldl 选项作用

    如果你的程序中使用dlopen.dlsym.dlclose.dlerror 显示加载动态库,需要设置链接选项 -ldl 加载动态链接库,首先为共享库分配物理内存,然后在进程对应的页表项中建立虚拟页和物 ...

  10. one or more

    想到以后如果一直都是这样,那么以后的生活是多么多么可怕啊. 感觉毫无期盼.没有意义. 如果变得理所当然那是多么多么让人害怕的事,吓得让人发抖. 所以在以后漫长的岁月里,还是一个人吧 如果相互看不惯,感 ...