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).

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

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致