PHPExcel文件如何导入成数组(选择指定的列)?

2019-06-18 浏览:129
PHPExcel文件如何导入成数组(选择指定的列)?
评论:(0)复制地址
            $filename="001.xls";                
            require "PHPExcel/Classes/PHPExcel/IOFactory.php";//引入读取excel的类文件
                date_default_timezone_set('PRC');
                $fileType=PHPExcel_IOFactory::identify($filename);//自动获取文件的类型提供给phpexcel用
                $objReader=PHPExcel_IOFactory::createReader($fileType);//获取文件读取操作对象
                try {
                    $inputFileType = PHPExcel_IOFactory::identify($filename);
                    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
                    $objPHPExcel = $objReader->load($filename);
                } catch (Exception $e) {
                    die('加载文件发生错误:"' . pathinfo($filename, PATHINFO_BASENAME) . '": ' . $e->getMessage());
                }
                $sheet = $objPHPExcel->getSheet(0);
                $highestRow = $sheet->getHighestRow();
                $highestColumn = $sheet->getHighestColumn();
                for($i=1;$i<=$highestRow;$i++)
                {   
                  
                    $data=array();
                    $data['A']=$objPHPExcel->getActiveSheet()->getCell("A".$i)->getValue();  
                    $data['B']=$objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
                    $data['C']=$objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();  
                    $data['D']=$objPHPExcel->getActiveSheet()->getCell("D".$i)->getValue(); 
                    $data['E']=$objPHPExcel->getActiveSheet()->getCell("E".$i)->getValue();  
                    $d[] = $data;
                }
echo json_encode( $d );


评论:(0)复制地址
发布:苗景云 | 分类:IT技术&设计 | Tags:PHPExcel

相关文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。