包含phpexcel类库文件,如果不能确定文件类型的话可以使用phpexcel_iofactory::identify方法返回文件的类型,传递给该函数一个文件名就可以。
<?php
    require_once('
include/common.inc.php');
    require_once(rootpath . 'include/phpexcel/phpexcel/iofactory.php');
    
    $filepath = './file/xls/110713.xls'; 
    
    $filetype = phpexcel_iofactory::identify($filepath); //文件名自动判断文件类型
    $objreader = phpexcel_iofactory::createreader($filetype);
    $objphpexcel = $objreader->load($filepath);
    
    $currentsheet = $objphpexcel->getsheet(0); //第一个工作簿
    $allrow = $currentsheet->gethighestrow(); //行数
    $output = array();
    $pretype = '';
    
    #// www.jb200.com
    $qh = $currentsheet->getcell('a4')->getvalue();
    //按照文件格式从第7行开始循环读取数据
    for($currentrow = 7;$currentrow<=$allrow;$currentrow++){ 
        //判断每一行的b列是否为有效的序号,如果为空或者小于之前的序号则结束
        $xh = (int)$currentsheet->getcell('b'.$currentrow)->getvalue();
        if(empty($xh))
break;
        
        $tmptype = (string)$currentsheet->getcell('c'.$currentrow)->getvalue(); //赛事类型
        if(!empty($tmptype))$pretype = $tmptype;
        $output[$xh]['type'] = $pretype;
        $output[$xh]['master'] = $currentsheet->getcell('f'.$currentrow)->getvalue(); //主队
        $output[$xh]['guest'] = $currentsheet->getcell('h'.$currentrow)->getvalue(); //客队    
    }
    
    //从当前行开始往下循环,取出第一个不为空的行
    for( ; ; $currentrow++){
        $xh = (int)$currentsheet->getcell('b'.$currentrow)->getvalue();
        if(!empty($xh))break;
    }
    
    for( ; $currentrow <= $allrow; $currentrow++){
        $xh = (int)$currentsheet->getcell('b'.$currentrow)->getvalue();
        if(empty($xh))break;
        
        $output[$xh]['rq'] = $currentsheet->getcell('i'.$currentrow)->getvalue();
    }
    header("content-type:text/html; charset=utf-8");
    
    echo '期号:' . $qh . "nn";
    if(!empty($output)){
        printf("%-5st%-15st%-40st%-40st%-5sn", '序号', '赛事类型', '主队', '客队', '让球值');
        foreach($output as $key => $row){
            $format = "%-5dt%-15st%-40st%-40st%-5sn";
            printf($format, $key, $row['type'], $row['master'], $row['guest'], $row['rq']);
  }
}
?>