title: Merging cells in Excel by rows and columns together using PHPExcel
body: <p>I need to merge cells in Excel (xlsx) by rows and again by columns using <a href="http://phpexcel.codeplex.com/downloads/get/212184" rel="noreferrer"><code>PHPExcel</code></a>. I tried the following.</p>
  
  <pre><code>$sheet-&gt;mergeCells("G".($row_count+1).":G".($row_count+4));             
  $sheet-&gt;mergeCells("H".($row_count+1).":H".($row_count+4));             
  $sheet-&gt;mergeCells("I".($row_count+1).":I".($row_count+4));     
  </code></pre>
  
  <p>Where the variable <code>$row_count</code> has some unpredictable dynamic value like 25, 50, 75 and so on (no regular pattern).</p>
  
  <p><img src="https://i.stack.imgur.com/hQBjc.png" alt="enter image description here"></p>
  
  <p>It merges the cells as shown in the preceding <a href="https://i.stack.imgur.com/hQBjc.png" rel="noreferrer">snap shot</a> as can be seen immediately below the <strong>Note</strong> cell. After merging these cells by rows, I'm trying to merge them by columns as follows.</p>
  
  <pre><code>$sheet-&gt;mergeCells("G".($row_count+1).":I".($row_count+1));             
  </code></pre>
  
  <p>but it doesn't work. When I try to open the excel file, it asks for a confirmation (with a confirmation box)</p>
  
  <blockquote>
    <p>Excel found unreadable content in 'report.xlsx'. Do you want to
    recover the contents of this workbook? If you trust the source of this
    workbook, click Yes.</p>
  </blockquote>
  
  <p>How to merge cells by rows and columns together in Excel then?</p>