How to get row after perform search

Topics: Developer Forum
Jul 3, 2014 at 2:55 AM
Edited Jul 3, 2014 at 4:50 AM
Hi,

I'm wondering on how to get the row after perform search?

class myExcelClass {
    public $objPHPExcel;
    public $cellValues;

    function __construct($filename) {
        $this->objPHPExcel = PHPExcel_IOFactory::load ( $filename );
    }

    public function getCellValues($currSheet) {
        $sheet = $currSheet;

        //echo "current sheet:".$sheet->getTitle()."<br />";

        $highestColumn = $sheet->getHighestColumn ();
        $highestColumnIndex = PHPExcel_Cell::columnIndexFromString ( $highestColumn );
        $highestRow = $sheet->getHighestRow ();

        $this->cellValues = array ();
        for($i = 0; $i < $highestColumnIndex; $i ++) {
            $column = PHPExcel_Cell::stringFromColumnIndex ( $i );
            for($j = 1; $j <= $highestRow; $j ++) {
                $this->cellValues [$column . $j] = $sheet->getCellByColumnAndRow ( $i, $j )->getValue ();
            }
        }
        return $this->cellValues;
    }


    public function getCellByValue($sheet, $search) {
        $nonPrintableChars = array (
                "\n",
                "\r",
                "\t",
                "\s" 
        );

        // return multi cells
        $retCells = array ();

        $search = str_replace ( $nonPrintableChars, '', $search );
        foreach ( $this->getCellValues ( $sheet ) as $cell => $value ) {
            if (strcasecmp ( str_replace ( $nonPrintableChars, '', $value ), $search ) == 0) {  
                array_push ( $retCells, $cell );
            }
        }
        return $retCells;
    }
}

$tempfile = "template.xls";
$outputfile = "outputReport" . uniqid () . ".xls";```

    $myexcel = new myExcelClass ( $tempfile );

///////----Replace Tag----///////////////   
$r = array (
        "date" => "6/7/2015",
        "refNo" => "Our Ref ARB/RS2010/KOBETA/(Testing)",
        "settlementDate1" => "5/21/2014",
        "settlementDate2" => "6/21/2014",
        "settlementDate3" => "7/21/2014"
);

foreach ( $myexcel->objPHPExcel->getWorksheetIterator () as $sheet ) {
    foreach ( $r as $k => $v ) {
        $cells = $myexcel->getCellByValue ( $sheet, '<' . $k . '>' );

        foreach($cells as $cell) {
            $sheet->setCellValue ( $cell, $v );
        }
    }
}
}
``` Im trying to get row of every element in an array.

Thank you