title: How to merge column in Excel using PHPExcel
body: <p>I already checked this <a href="https://stackoverflow.com/questions/10909598/merging-cells-in-excel-by-rows-and-columns-together-using-phpexcel">Merging cells in Excel by rows and columns together using PHPExcel</a> but its showing only for row addition however I applied some tests for column as well but none is working.</p>
  
  <p>This code although creates the excel sheet successfully but the output in excel is throwing error.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>however this is working if remove the llop and put this in simple terms -</p>
  
  <pre><code>$objPHPExcel-&gt;setActiveSheetIndex(0)-&gt;mergeCells('A1:B1');
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A1', 'Swapnesh');
  </code></pre>
  
  <p>Main code for adding the data - </p>
  
  <pre><code>// Add some data
  echo date('H:i:s') , " Add some data" , EOL;
  $i = "A";
  $j ="B";
  for($num =1; $num &lt;= 5; $num++ )
  {
      $concat =  "{$i}1:{$j}1";
      $objPHPExcel-&gt;setActiveSheetIndex(0)-&gt;mergeCells($concat);
      $i++;$j++;
  } 
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A1', 'Swapnesh');
  </code></pre>
  
  <p>My whole code -</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', TRUE);
  ini_set('display_startup_errors', TRUE);
  
  define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '&lt;br /&gt;');
  
  date_default_timezone_set('Asia/Calcutta');
  
  /** Include PHPExcel */
  require_once 'Classes/PHPExcel.php';
  
  
  // Create new PHPExcel object
  echo date('H:i:s') , " Create new PHPExcel object" , EOL;
  $objPHPExcel = new PHPExcel();
  
  // Set document properties
  echo date('H:i:s') , " Set document properties" , EOL;
  $objPHPExcel-&gt;
  getProperties()-&gt;setCreator("Swapnesh Sinha")
                               -&gt;setLastModifiedBy("Swapnesh")
                               -&gt;setTitle("Office 2007 XLSX Test Document")
                               -&gt;setSubject("Office 2007 XLSX Test Document")
                               -&gt;setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
                               -&gt;setKeywords("office 2007 openxml php")
                               -&gt;setCategory("Test result file");
  
  
  // Add some data
  echo date('H:i:s') , " Add some data" , EOL;
  $i = "A";
  $j ="B";
  for($num =1; $num &lt;= 5; $num++ )
  {
      $concat =  "{$i}1:{$j}1";
      $objPHPExcel-&gt;setActiveSheetIndex(0)-&gt;mergeCells($concat);
      $i++;$j++;
  } 
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A1', 'Swapnesh');
  
  // Rename worksheet
  echo date('H:i:s') , " Rename worksheet" , EOL;
  $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle('Student Data');
  
  
  // Set document security
  echo date('H:i:s') , " Set document security" , EOL;
  $objPHPExcel-&gt;getSecurity()-&gt;setLockWindows(true);
  $objPHPExcel-&gt;getSecurity()-&gt;setLockStructure(true);
  $objPHPExcel-&gt;getSecurity()-&gt;setWorkbookPassword("PHPExcel");
  
  
  // Set sheet security
  echo date('H:i:s') , " Set sheet security" , EOL;
  $objPHPExcel-&gt;getActiveSheet()-&gt;getProtection()-&gt;setPassword('PHPExcel');
  $objPHPExcel-&gt;getActiveSheet()-&gt;getProtection()-&gt;setSheet(true); // This should be enabled in order to enable any of the following!
  $objPHPExcel-&gt;getActiveSheet()-&gt;getProtection()-&gt;setSort(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getProtection()-&gt;setInsertRows(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getProtection()-&gt;setFormatCells(true);
  
  
  // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  
  
  // Save Excel 2007 file
  echo date('H:i:s') , " Write to Excel2007 format" , EOL;
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  //$objWriter-&gt;save(str_replace('.php', '.xlsx', __FILE__));
  $filename = "Student-data-sheet".".xlsx";
  $objWriter-&gt;save($filename);
  echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  
  
  // Echo memory peak usage
  echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
  
  // Echo done
  echo date('H:i:s') , " Done writing file" , EOL;
  echo 'File has been created in ' , getcwd() , EOL; 
  </code></pre>