站长论坛

标题: PHPExcel读取Excel文件 [打印本页]

作者: superadmin    时间: 2010-6-11 14:14
标题: PHPExcel读取Excel文件
$fileName = 'excel.xls';   
$path = 'path';   
$filePath = $path.$fileName;   
$PHPExcel = new PHPExcel();        
$PHPReader = new PHPExcel_Reader_Excel2007();                  
if(!$PHPReader->canRead($filePath)){                        
    $PHPReader = new PHPExcel_Reader_Excel5();     
    if(!$PHPReader->canRead($filePath)){                        
        echo 'no Excel';   
        return ;   
    }   
}   
$PHPExcel = $PHPReader->load($filePath);   
$currentSheet = $PHPExcel->getSheet(0);   
/**取得一共有多少列*/  
$allColumn = $currentSheet->getHighestColumn();      
/**取得一共有多少行*/  
$allRow = array($currentSheet->getHighestRow());     
  
for($currentRow = 1;$currentRow<=$allRow;$currentRow++){   
    for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){   
        $address = $currentColumn.$currentRow;   
           
        echo $currentSheet->getCell($address)->getValue()."\t";   
    }   
    echo "\n";   
}




欢迎光临 站长论坛 (https://tzlink.com/bbs/) Powered by Discuz! X3.2