douhongxie5436
2015-07-27 09:33
浏览 92
已采纳

Symfony 2:如何在PHPExcel中读取excel文件内容

I am using PHPExcel with Symfony 2 and showing the content of an excel file like this:

    $users = array();
    foreach($excel as $i=>$row) {
    if($i !== 1) {          
        array_push($users,array(
            'row'=>$i,
            'name'=>$row['A'],
            'lastname'=>$row['B']
//...and so on

        ));         
    }

}

Question:
How can I show the content using the row name instead of $row['A']..ect?
As $row['name']... I mean the name of the excel row.
Example:
A = name B = email...and so on... I would like to show the content like this:

    $users = array();
    foreach($excel as $i=>$row) {
    if($i !== 1) {          
        array_push($users,array(
            'row'=>$i,
            'name'=>$row['name'],
            'lastname'=>$row['surname']
//...and so on

        ));         
    }

}
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douping6871 2015-07-27 10:48
    已采纳

    I'm pretty sure that I answered this question barely a week ago.... assuming that row #1 contains your headers:

    if($i == 1) {
        $headers = $row;
    } else {
        $row = array_combine($headers, $row);
        array_push($users,array(
            'row'=>$i,
            'name'=>$row['name'],
            'lastname'=>$row['surname']
            //...and so on
    
        ));         
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题