php - How to get row id using color code in phpexcel -


i have excel file contains rows color want row id of particular color code unable .. searched found nothing below code phpexcel

$cellcolor = $objphpexcel->getactivesheet()->getstyle($cell->getcoordinate())->getfill()->getstartcolor()->getrgb(); 

this give me color code , value have $cell->getvalue() $cell variable $celliterator

  foreach ($worksheet->getrowiterator() $row) {     $celliterator = $row->getcelliterator();     $celliterator->setiterateonlyexistingcells(false);              foreach ($celliterator $cell)              {               $cellcolor = $objphpexcel->getactivesheet()->getstyle($cell->getcoordinate())->getfill()->getstartcolor()->getrgb();              if (!empty($cell->getcalculatedvalue())) {                    if ($cellcolor == 'yellow') {                         echo ($cellcolor.'======'.$cell->getvalue());                    }                }             }    } 

$cell->getvalue() give me value of particular color code
but, problem if have 2 rows color yellow $cell->getvalue() give 2 value
0-> yellow1
1-> yellow2
but after deleting 1st yellow colour data in excel result
0-> yellow2
which wrong need
0->''
1-> yellow2
thats why need row id particular color can identify row.

after hours of practicing got expected result

$objphpexcel = phpexcel_iofactory::load('somefile.xls'); foreach ($objphpexcel->getworksheetiterator() $worksheet) {      //$worksheettitle = $worksheet->gettitle();     $highestrow = $worksheet->gethighestrow();     $highestcolumn = $worksheet->gethighestcolumn();     $highestcolumnindex = phpexcel_cell::columnindexfromstring($highestcolumn);     //$nrcolumns = ord($highestcolumn) - 64;      $groupcount = array();     $standardsetcount = array();     $standardcount = array();     $learningtargetcount = array();      ($row = 1; $row <= $highestrow; ++$row) {         ($col = 0; $col < $highestcolumnindex; ++$col) {             $cell = $worksheet->getcellbycolumnandrow($col, $row);             $colorcode = $objphpexcel->getactivesheet()->getstyle($cell->getcoordinate())->getfill()->getstartcolor()->getrgb();              /*              * yellow               */              if ($colorcode == 'ffff00') {                 $val = $cell->getvalue();                 //$datatype = phpexcel_cell_datatype::datatypeforvalue($val);                 $groupcount[] = $val;   // $groupcount[] = $datatype;             }              /*              * gold              */              if ($colorcode == 'cc9900') {                 $val = $cell->getvalue();                 $standardsetcount[] = $val;             }              /*              * red              */              if ($colorcode == 'ff3333') {                 $val = $cell->getvalue();                 $standardcount[] = $val;             }              /*              * green              */              if ($colorcode == '00cc33') {                 $val = $cell->getvalue();                 $learningtargetcount[] = $val;             }         }     }      $group = (array_chunk($groupcount, $highestcolumnindex));     $standardset = (array_chunk($standardsetcount, $highestcolumnindex));     $standard = (array_chunk($standardcount, $highestcolumnindex));     $learningtarget = (array_chunk($learningtargetcount, $highestcolumnindex));      echo '<pre>';     print_r($learningtarget); } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -