title: PHPExcel mergeCells every 2n column
body: <p>I have some data in array <code>$header1</code>, <code>$header2</code> and <code>$data</code>. The case is to insert all these arrays to excel file where header is already ready, that is: </p>
  
  <p><a href="https://i.stack.imgur.com/yPK6I.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yPK6I.jpg" alt="enter image description here"></a></p>
  
  <p>Another headers will be set after inserting of <code>$header1</code> and <code>$header2</code>. 
  Now the main issue is to insert <code>$header1</code> array to merged column: </p>
  
  <p><a href="https://i.stack.imgur.com/RtqY6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RtqY6.jpg" alt="enter image description here"></a></p>
  
  <p>Or first insert data and then merge them: </p>
  
  <p><a href="https://i.stack.imgur.com/RySgw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RySgw.jpg" alt="enter image description here"></a></p>
  
  <p>From my side I have tried a lot of solutions , but nothing... </p>
  
  <p><strong>MY CODE :</strong> </p>
  
  <pre><code>$excel2-&gt;setActiveSheetIndex(4);
  $row = 6;
  $col = 2;
  $col_letter = 'D';
  foreach($header1 as $key=&gt;$value) {
      $excel2-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow($col, $row, $value);
      $col=$col+2;
      $merge = "'".$col_letter.$row.":".(++$col_letter).$row."'";
      $excel2-&gt;getActiveSheet()-&gt;mergeCells($merge);
      $col_letter++;
  }
  </code></pre>
  
  <p>Take into account that <code>$header1</code> array's data is unpredictable and the count of data can be over 50. </p>
  
  <p>Any suggestion will be appreciated. Thanks. </p>