title: Insert formula in each cell based on amount of rows
body: <p>Any help appreciated..</p>
  
  <p>My Code</p>
  
  <pre><code>        /**
   *  Admin Excel Export Function().
   */
  
  function work_record_export_admin(){
  
  
  require('inc/php-excel.class.php');
  
  
  
      $objPHPExcel = new PHPExcel();
      $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle('Work Record');
  
      $objPHPExcel-&gt;setActiveSheetIndex(0)
              -&gt;setCellValue('A1', 'Name')
              -&gt;setCellValue('B1', 'Region')
              -&gt;setCellValue('C1', 'Role')
              -&gt;setCellValue('D1', 'Date')
              -&gt;setCellValue('E1', 'Start Travel')
              -&gt;setCellValue('F1', 'Start Job')
              -&gt;setCellValue('G1', 'Finish Job')
              -&gt;setCellValue('H1', 'Site ID')
              -&gt;setCellValue('I1', 'Site Name')
              -&gt;setCellValue('J1', 'Site Town')
              -&gt;setCellValue('K1', 'Fault Description')
              -&gt;setCellValue('L1', 'Work Summary')
          -&gt;setCellValue('M1', 'Customer Type')
              -&gt;setCellValue('N1', 'Business')
              -&gt;setCellValue('O1', 'Work Code (depot only)')
              -&gt;setCellValue('P1', 'Quantity (depot only)')
          -&gt;setCellValue('Q1', 'Travel Time')
              -&gt;setCellValue('R1', 'Job Time');
  
   $result = db_query("SELECT name, region, role, date, startt, startj, finj, siteid, sitename, sitetown, faultdesc, worksum, buscode, workcode, quantity FROM work_record_grid ") or die('Query failed!'); 
  
    // Loop through the result set
      $rowNumber = 2;
      while ($row = db_fetch_array($result)) {
         $col = 'A';
         foreach($row as $cell) {
            $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($col.$rowNumber,$cell);
            $col++;
         }
         $rowNumber++;
      }
  
      // Freeze pane so that the heading line won't scroll
      $objPHPExcel-&gt;getActiveSheet()-&gt;freezePane('A2');
  
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('A')-&gt;setWidth(20);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('B')-&gt;setWidth(17);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('C')-&gt;setWidth(19);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('D')-&gt;setWidth(12);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('E')-&gt;setWidth(10);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('F')-&gt;setWidth(10);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('G')-&gt;setWidth(10);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('H')-&gt;setWidth(10);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('I')-&gt;setWidth(17);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('J')-&gt;setWidth(17);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('K')-&gt;setWidth(20);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('L')-&gt;setWidth(30);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('M')-&gt;setWidth(14);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('N')-&gt;setWidth(20);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('O')-&gt;setWidth(21);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('P')-&gt;setWidth(8);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('Q')-&gt;setWidth(10);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('R')-&gt;setWidth(10);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('Q'.$row)-&gt;getNumberFormat()-&gt;setFormatCode('[h]:mm');
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('R'.$row)-&gt;getNumberFormat()-&gt;setFormatCode('[h]:mm');
  //$objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('Q'.$row, '=(F'.$row.'-E'.$row.')');
  //$objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue(R'.$row, '=(G'.$row.'-F'.$row')');
  
      // Save as an Excel BIFF (xls) file
      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="work_record_data' . date('Ymd') . '.xls"');
     header('Cache-Control: max-age=0');
     $objWriter-&gt;save('php://output');
     exit();
  
   }
  </code></pre>
  
  <p>I'm trying to add the formula =F(cellnumber)-E(cellnember) into all of the cells in the Q col.  and =G(cellnumber)-E(cellnumber) into all of the R col. for each row that exists.</p>
  
  <p>thanks in advance</p>