dsfh40613182 2016-02-08 11:17
浏览 73
已采纳

找到PHPExcel行中的最高列

I am triying to read all columns from an excel file but its number is variable depending on the row. For example: Row1, col2, col3, col4 Row2, col2,col3 Row3,col2,col3,col4,col5,col6

I am trying to do something like:

for ($row = 1; $row < 2; $row++){
    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
    echo print_r($rowData[0][0]);
    echo "<br>";
    $list_of_coordinates = "";
    $i = 1;
    //echo print_r($rowData[$row][$i+1]);
    while($rowData[0][$i+1] != ""){
      /*$list_of_coordinates = $list_of_coordinates . 
                             "," .
                             $rowData[0][$i+1] . 
                             "," .
                             $rowData[0][$i];
      */
      $i+2;
    }
    $list_of_coordinates = ltrim($list_of_coordinates, ",");
    echo $list_of_coordinates;
    echo "<br>";
  }

But the $highestcolumn has the column number of the maximum one, in this file: BM. But some of the rows have just 3 or 4 columns. Is it possible to update this number? MY while loop is not working right now.

  • 写回答

1条回答 默认 最新

  • duankangzi766767 2016-02-08 11:35
    关注

    The getHighestColumn() and getHighestDataColumn() methods accept an optional row number as an argument. If called without passing any argument, they will return the highest column number in the worksheet; but if called with a row number, they will return the highest column in the specified row.

    However, as an alternative, you could use the row and column iterators, for existing cells only (see 28iterator.php in /Examples).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献