title: PHPExcel Background Color Logic
body: <p>I have a very confusing issue with PHPExcel. I have 800 students. I'm generated a spreadsheet which lists how much praise (on a daily basis for the current month) that the student has has.</p>
  
  <p>For instance, it may look like this:</p>
  
  <pre><code>+---------------+-----+-----+-----+-----+
  | Student Name  | 1st | 2nd | 3rd | 4th | ...
  +---------------+-----+-----+-----+-----+
  | Test Student  | 2   | 0   | 3   | 7   |
  +---------------+-----+-----+-----+-----+
  </code></pre>
  
  <p>I want to change the background color of the cells which are greater (or equal to) 5. I use a loop to loop over the students, and days. This is my code:</p>
  
  <pre><code>for($d=1; $d&lt;=$daysInCMonth; $d++)
  {
      $phpExcel
          -&gt;getSheetByName('Monthly Leaderboard')
          -&gt;setCellValue($alphabetArray[($d+7)] . ($recordCount+5), $record['monthlyReport'][$MonthlyReportKeys[($d-1)]]);
  
      if($record['monthlyReport'][$MonthlyReportKeys[($d-1)]]&gt;=5)
      {
          $cellId = $alphabetArray[($d+7)] . ($recordCount+5);
          $phpExcel
              -&gt;getSheetByName('Monthly Leaderboard')
              -&gt;getStyle($cellId)
              -&gt;applyFromArray(
                  array('fill' =&gt; array('type' =&gt; PHPExcel_Style_Fill::FILL_SOLID,'color' =&gt; array('rgb' =&gt; '000000'))
           ));
      }
  
  }
  </code></pre>
  
  <p>To help understand the code, the initial <code>for</code> loop loops through from 1 up until the number of days in the current month (IE 30 for June). It then sets cells value as the number of points for each given day. </p>
  
  <p>This all works perfectly. Now, the <code>if</code> condition will catch cells which have a value of greater (or equal to) 5. </p>
  
  <p>The code <code>$alphabetArray[($d+7)] . ($recordCount+5)</code> grabs the current cell ID in the iteration. I know this works fine as well, because if I echo it to the screen, the first output is <code>T5</code> which is a cell greater than 5.</p>
  
  <p>If I implicitly specify <code>T5</code> as the cell to color, it works fine. However, if I try to use the value of <code>$cellId</code> to dynamically color all cells for my condition, none of the cells are colored.</p>
  
  <p>I know the cell ID is 100% correct, I know the coloring statement is correct (as it does color cells if I refer to them specifically). It just doesn't want to play dynamically.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks
  Phil</p>