tp3.2读取excel文件

使用PHPExcel时,首先要下载PHPExcel并放在ThinkPHP/Library/Vendor下

1.创建html文件(文件上传按钮)

       

       

2.后台处理上传的文件

public function xxxx(){
        $file = $_FILES;
        if($file){
            $upload = new \Think\Upload();
            if (!$info = $upload->upload()) {
                $this->error($upload->getError());
            }
            $file_name=$upload->rootPath.$info['import']['savepath'].$info['import']['savename'];
            $extension = $info['import']['ext'];
            //引入excel操作类
            vendor("PHPExcel.PHPExcel");
            if($extension == "xlsx"){
                $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
            }else{
                $objReader = \PHPExcel_IOFactory::createReader('Excel5');
            }
            $objPHPExcel = $objReader->load($file_name,$encode='utf-8');
            $sheet = $objPHPExcel->getSheet(0);

            //excel中每个单元格中的数据
            $excelData = $sheet->toArray();
        }else{
            $this->display();
        }
  }

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0