PHP导入Excel文件

php

浏览数:276

2019-1-8

AD:资源代下载服务
    setLoadSheetsOnly($sheetName);  
    $objPHPExcel = $objReader->load($filename);  
    //全部加载  
    //$objPHPExcel = PHPExcel_IOFactory::load($filename); //加载文件  

    //全部读取  
    /* 
    $sheetCount = $objPHPExcel->getSheetCount(); 
    for($i=0; $i<$sheetCount; $i++){ 
        $data = $objPHPExcel->getSheet($i)->toArray(); //读取数据到数组 
        var_dump($data); 
    }*/  
    //逐行读取  
    foreach($objPHPExcel->getWorkSheetIterator() as $sheet){  
        foreach($sheet->getRowIterator() as $row){  
            if($row->getRowIndex() < 2) continue; //忽略第一行  
            foreach ($row->getCellIterator() as $cell) {  
                $data = $cell->getValue();  
                echo $data.' ';  
            }  
            echo '
'; } echo '

'; }