PhpExcel 的导入导出

来源:互联网 发布:徐静蕾开淘宝店么 编辑:程序博客网 时间:2024/05/16 19:52

成功后的代码

    //导入卡券    public function import_excel(){        if(Request::instance()->isPost()){            $activity = request() -> post();            $file = Request()->file('file');//获取表单提交过来的文件            $error = $_FILES['file']['error']; //如果0,表示文件上传失败            if(!$error){                $i = 0;                $import_model = new ImportCouponModel();                $dir= ROOT_PATH . 'public' .DS. 'uploads';//定义excel文件存放路径                $info = $file->move($dir);                //移动excel文件到应用根目录/public/uploads/目录下                Vendor("PHPExcel.IOFactory");//引入iof文件                $filename= $dir. DS . $info->getSaveName();//excel文件的全路径                $objPHPExcel=\PHPExcel_IOFactory::load($filename);//加载文件                foreach($objPHPExcel->getWorksheetIterator() as $sheet){//循环取sheet                    foreach($sheet->getRowIterator() as $row){//逐行处理                        if($row->getRowIndex()<2){//从第二行开始读取                            continue;                        }                        foreach($row->getCellIterator() as $cell){//逐列读取                            $data = array();                            $one_data=$cell->getValue();                            $data['coupon_code'] = $one_data;                            $data['activity_id'] = $activity['activity_id'];                            $import_model -> add_coupon($data);                        }                    }                }            }else{                $this -> error('您没有excel文件请添加文件。');            }            unlink($filename);//当处理完数据后,删除excel表        }        $this->success('导入文件成功。');    }

第三方链接

http://fity.cn/post/621.html
http://www.cnblogs.com/liamqm/p/6185174.html
http://www.cnblogs.com/freespider/p/3284828.html

原创粉丝点击