douhongxie5436 2015-07-27 01:33 采纳率: 100%
浏览 95
已采纳

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 02: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
    
        ));         
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了