Need help regarding Cell Count

Topics: Developer Forum, User Forum
Apr 5, 2012 at 4:10 AM

Hello there, I am a beginner in PHP and PHPExcel, I need some help regarding the cell count. I have a code that extract logs of of our web application and extracts them onto excel sheet with various parameters such as venue search, venu print, event search, event print, itinerary print. All the parameters from our application are displayed on excel sheet with date, time and keywords searched for. Few of the parameters are displayed in bold and in different coulours such as event search, event print are displayed in bold on the excel sheet. Now I want to display the number of times a parameter is occurring on the sheet, for example if 'event search' parameter is occurring 20 times on the sheet, I want to display the number of times 'event search' is occurring in the sheet. I hope I am clear enough with my question, I can provide the full if needed

$command = $data['command'];
                switch($command) {

                        case "venue search" :
                              $color = "808080";
                              $font = 'bold';
                                break;
                        case "venue print" :
                              $color = "4169E1";
                              $font = 'bold';
                               break;
                        case "event print" :
                                $color = "008000";
                                $font = 'bold';
                                break;
                        case "recommended events print" :
                                $color = "008000";
                                $font = 'bold';
                                break;
                        case 'itinerary print' :
                             $color = "FF0000";
                             $font = 'bold';
                                break;
                        default:
                               $color = '000000';
                               $font = 'regular';
                               break;
                }

                $curr_row++;
//  echo "'$command': B$curr_row -> $color\n";
                      $objPHPExcel->getActiveSheet()->getStyle("B".$curr_row)->applyFromArray(array('font' => array($font => true)));
                      $objPHPExcel->getActiveSheet()->getStyle("B".$curr_row)->getFont()->getColor()->applyFromArray(array('rgb' => $color))
The above is few lines of code, I can upload the full code if needed. Thanks in advance.

Coordinator
Apr 5, 2012 at 8:12 PM

If you're using Excel2007, then the Excel formula:

=COUNTIF(A1:A100,"Event Search");

will count the number of occurrences of "Event Search" in cell range A1:A100

Apr 6, 2012 at 2:50 AM

Thanks a ton Mark, my bad that i wasn't looking for a simple formula, you save my data. Thanks a again!