11

我正在使用 PHPExcel 从xls文件中读取一些数据。

我想一次获得几个单元格,例如:A6 - A11。

我知道我可以$cell = $objPHPExcel->setActiveSheetIndex(0)->getCell('A6');用来获取单个单元格,并且我可能会遍历一个数组并获取我范围内的每个单元格。

但是,难道没有更简单的方法来获得类似的单元格范围getCellRange('A6:A11')吗?

4

1 回答 1

22

有,rangeToArray()方法:

$objPHPExcel->setActiveSheetIndex(0)->rangeToArray('A1:C3');

想知道为什么我首先要费心记录这些方法,但这里也是参数列表:

/**
 *  Create array from a range of cells
 *
 *  @param   string    $pRange              Range of cells (i.e. "A1:B10"),
 *                                             or just one cell (i.e. "A1")
 *  @param   mixed     $nullValue           Value returned in the array entry 
 *                                             if a cell doesn't exist
 *  @param   boolean   $calculateFormulas   Should formulas be calculated?
 *  @param   boolean   $formatData          Should formatting be applied to cell values?
 *  @param   boolean   $returnCellRef       False - Return a simple array of rows 
 *                                             and columns indexed by number counting
 *                                             from zero
 *                                         True - Return rows and columns indexed by 
 *                                             their actual row and column IDs
 *  @return array
 */
于 2013-08-13T08:05:02.977 回答