title: PHPExcel set cell value dynamically
body: <p><strong>This is my code of getting the data of my excel file...</strong></p>
  
  <pre><code>    require_once 'IOFactory.php';
      $objPHPExcel = PHPExcel_IOFactory::load("NAV USER ACCESS Calculation.xlsx"); 
      $objPHPExcel-&gt;setActiveSheetIndex(2);
  
      $worksheet = $objPHPExcel-&gt;getActiveSheet();
  
      $worksheetTitle     = $worksheet-&gt;getTitle();
      $highestRow         = $worksheet-&gt;getHighestRow(); // e.g. 10
      $highestColumn      = $worksheet-&gt;getHighestColumn(); // e.g 'F'
      $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
      $nrColumns = ord($highestColumn) - 64;
      echo '&lt;div id="table-cont"&gt;
          &lt;table border="1"&gt;';
      for ($row = 1; $row &lt;= $highestRow; ++ $row)
      {
          echo '&lt;tr&gt;';
          for ($col = 0; $col &lt; $highestColumnIndex; ++ $col)
          {
              $cell = $worksheet-&gt;getCellByColumnAndRow($col, $row);
              $val = $cell-&gt;getValue();
              $val =$cell-&gt;getCalculatedValue();
              $val =$cell-&gt;getFormattedValue();
  
              $dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
              echo '&lt;td&gt;' . $val . '&lt;/td&gt;';
          }
          echo '&lt;/tr&gt;';
      }
      echo '&lt;/table&gt;
          &lt;div id="clock"&gt;&lt;/div&gt;
          &lt;/div&gt;';
  </code></pre>
  
  <p><strong>And this is my code of setting my table into excel, but i dont know whats wrong...</strong></p>
  
  <pre><code>    $serverName="192.168.1.253";
      $conInfo=array("Database"=&gt;"dbName","UID"=&gt;"sa","PWD"=&gt;"xxxxx");
      $con= sqlsrv_connect($serverName,$conInfo);
  
      require_once 'IOFactory.php';
      $objPHPExcel = PHPExcel_IOFactory::load("NAV USER ACCESS Calculation.xlsx"); 
      $objPHPExcel-&gt;setActiveSheetIndex(2);
  
      $worksheet = $objPHPExcel-&gt;getActiveSheet();
  
      $worksheetTitle     = $worksheet-&gt;getTitle();
      $highestRow         = $worksheet-&gt;getHighestRow(); // e.g. 10
      $highestColumn      = $worksheet-&gt;getHighestColumn(); // e.g 'F'
      $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
      $nrColumns = ord($highestColumn) - 64;
      echo '&lt;div id="table-cont"&gt;
          &lt;table border="1"&gt;';
      $sql= sqlsrv_query($con,"SELECT * FROM dbo.[Active Session]");
      while($data=sqlsrv_fetch_array($sql))
      {
          for ($row = 1; $row &lt;= $highestRow; ++ $row)
          {
              echo '&lt;tr&gt;';
              for ($col = 0; $col &lt; $highestColumnIndex; ++ $col)
              {
                  $cell = $worksheet-&gt;setCellValueByColumnAndRow($col, $row);
                  $val = $cell-&gt;getValue();
                  $val =$cell-&gt;getCalculatedValue();
                  $val =$cell-&gt;getFormattedValue();
  
                  $dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
                  echo '&lt;td&gt;' . $val . '&lt;/td&gt;';
              }
              echo '&lt;/tr&gt;';
          }
      }
      echo '&lt;/table&gt;
          &lt;div id="clock"&gt;&lt;/div&gt;
          &lt;/div&gt;';
  </code></pre>