0

I want to get cell value from a specific column in the row object:

$this->parsedExcelFile; //this is the worksheet
    $rows = $this->parsedExcelFile->getActiveSheet()->getRowIterator(($this->startRowIndex+1));

    foreach($rows as $row){
        $values[] = $row->getCellFromColumn('B')->getValue();
        //in getCellFromColumn is the column index, lets say B
        //getCellFromColumn($par) is a fictional function, i can't find how to get cell from a 
        //certain column directly from the row object

    }

I don't want to get it with:

$this->parsedExcelFile->getCell('B'.$row->getRowIndex())->getValue();

And i don't want to loop trough all cells. Any help is welcome.

Lachezar Raychev
  • 2,113
  • 4
  • 24
  • 34

2 Answers2

1

I doubt there is any function getCellFromColumn() in phpExcel library. You can use the way it is retrieved in PHPExcel Column Loop

Community
  • 1
  • 1
Santosh Pradhan
  • 149
  • 1
  • 11
  • I already have written what the function is fictional .... meaning that it does not exist and if there is a function that would work, because i can't seem to find it... – Lachezar Raychev Mar 07 '14 at 19:20
1

Add this function to the PHPExcel_Worksheet_Row class

public function getColumnValue($column = 0) {
    if(is_int($column)) {
        return $this->_parent->getCellByColumnAndRow($column, $this->_rowIndex);
    }  

    return $this->_parent->getCell($column.$this->_rowIndex);
}

Subsequently, call the new function on each row object returned by the iterator, $row->getColumnValue($column)->getValue();, where $column is either the column index or the column alphabet.

EDIT: The PHPExcel_Worksheet_Row class is in the file row.php in directory Classes->PHPExcel->Worksheet.

tunmyse
  • 76
  • 5