phpPHPExcel: read part of the sheet

How to get part of the sheet, for example, only rows from 1 to 10 or from 20 to 30 etc?
Now im using this:

public function GetArray($from = false, $to = false) {
    $rowIterator = $this->objPHPExcel->getRowIterator();
    foreach ($rowIterator as $id=>$row) {

            if($id < $from) continue;

            if($id > $to) break;

        $cellIterator = $row->getCellIterator();
        foreach ($cellIterator as $cell) {
            $arResult[$id][] = trim($cell->getCalculatedValue());
    return $arResult;

But im think this is not the best solution.

Easiest method is to use the Worksheet's rangeToArray() method.

 * 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

Related Articles
You Might Also Like