Home > php教程 > php手册 > Yii中使用PHPexcel获取excel中数据

Yii中使用PHPexcel获取excel中数据

WBOY
Release: 2016-06-13 09:36:58
Original
1268 people have browsed it

1.view中代码如下:

 


                     请选择包含批量IP称的EXCEL文件
                   
                   
 

2.controller中代码如下:

 if(isset($_FILES['batchFile']) && $_FILES['batchFile']['error']==0)
       {
        spl_autoload_unregister(array('YiiBase','autoload'));  //注销YII的自动加载,采用手动导入,PHPexcel有自己的加载功能
            include_once(dirname(dirname(__FILE__)).'\extensions/PHPExcel.php');     //按照自己的路径导入类文件
        include_once(dirname(dirname(__FILE__)).'\extensions/PHPExcel/IOFactory.php');

           $objPHPExcel = PHPExcel_IOFactory::load($_FILES['batchFile']['tmp_name']);           //导入上传的excel文件的数据逻辑
           $objWorksheet = $objPHPExcel->getActiveSheet(0);                                               //获取excel中sheet(0)的数据
        spl_autoload_register(array('YiiBase','autoload'));                                                      //重新启用YII的自动载入
        
        $EXCEL_VALUE = array();
                 foreach ($objWorksheet->getRowIterator() as $row)                                             //遍历数据
        {
            $cellIterator = $row->getCellIterator();                                                        
            $cellIterator->setIterateOnlyExistingCells(true);
            foreach ($cellIterator as $cell) 
            {
                $EXCEL_VALUE[] = $cell->getValue();
            }
        }
             dump($EXCEL_VALUE);                                                                                            

这里我只用到这些,其他的还不是很清楚,继续研究。
参考:本人所用的PHPExcel版本为该地址资源:http://download.csdn.net/detail/btbdylq/3798155

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template