title: PHPExcel Cells over lapping each other >setRowHeight(-1) auto cell height not working
body: <hr />
  <h2>Update</h2>
  <blockquote>
  <p>Tested using <strong>PHPSpreadsheet</strong> I have this code below that I have tried. It seems to work on <strong>MSOffice Excel</strong> if I use xls when I write the file. <em>Note not working with <strong>Libre Office</strong> does not auto resize row need it to work with libre office as well.</em></p>
  </blockquote>
  <pre><code>$spreadsheet-&gt;getActiveSheet()-&gt;getRowDimension(1)-&gt;setRowHeight(-1);
  
  foreach($spreadsheet-&gt;getActiveSheet()-&gt;getRowDimensions() as $rowID) { 
      $rowID-&gt;setRowHeight(-1); 
  }
  </code></pre>
  <p>New Controller</p>
  <pre><code>&lt;?php
  
  require(APPPATH . 'vendor/autoload.php');
  
  use PhpOffice\PhpSpreadsheet\Spreadsheet;
  
  class Events extends MX_Controller {
  
      public function test() {
          $spreadsheet = new Spreadsheet();
  
          $spreadsheet-&gt;getDefaultStyle()-&gt;getFont()-&gt;setName('Arial');
          $spreadsheet-&gt;getDefaultStyle()-&gt;getFont()-&gt;setSize(24);
  
          foreach(range('A','B') as $columnID) {
              $spreadsheet-&gt;getActiveSheet()-&gt;getColumnDimension($columnID)-&gt;setAutoSize(true);
          }
  
          $spreadsheet-&gt;getActiveSheet()-&gt;getRowDimension(1)-&gt;setRowHeight(-1);
  
          foreach($spreadsheet-&gt;getActiveSheet()-&gt;getRowDimensions() as $rowID) { 
              $rowID-&gt;setRowHeight(-1); 
          }
  
          $spreadsheet-&gt;setActiveSheetIndex(0)
                  -&gt;setCellValue(&quot;A1&quot;,'Firstname')
                  -&gt;setCellValue(&quot;B1&quot;,'Lastname');
  
          $spreadsheet-&gt;getActiveSheet()-&gt;setTitle('Users Information');
  
          $spreadsheet-&gt;setActiveSheetIndex(0);
  
          /* Here there will be some code where you create $spreadsheet */
  
          // redirect output to client browser
          header('Content-Type: application/vnd.ms-excel');
          header('Content-Disposition: attachment;filename=&quot;myfile.xls&quot;');
          header('Cache-Control: max-age=0');
  
          $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
          $writer-&gt;save('php://output');
                  
          exit;
  
      }
  }
  </code></pre>
  <hr />
  <h2>Original Question</h2>
  <p>I am new to phpexcel When I download my file the cells are overlapping each other.</p>
  <p>As you can see in image the are all bunched up when have large font size.</p>
  <p><a href="https://i.stack.imgur.com/T3DrX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/T3DrX.png" alt="enter image description here" /></a></p>
  <blockquote>
  <p>Question How can I make sure the cells are not over lapping each other. I tried file in libreoffice &amp; msoffice excel and same issue.</p>
  </blockquote>
  <p>I have tried still no change</p>
  <pre><code>foreach(range('A','D') as $columnID) {
     $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension($columnID)
              -&gt;setAutoSize(true);
  }
      
  foreach (range('A', $objPHPExcel-&gt;getActiveSheet()-&gt;getHighestDataColumn()) as $col) {
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension($col)-&gt;setAutoSize(true);
  }
  
  foreach(range(1, 4) as $rowID) {
    $objPHPExcel-&gt;getActiveSheet()-&gt;getRowDimension($rowID)-&gt;setRowHeight(-1);
  }
  </code></pre>
  <p>Controller</p>
  <pre><code>&lt;?php
  
  class Events extends MX_Controller {
  
      public function generate_excel() {
  
          $query = $this-&gt;db-&gt;get('event');
          $excelresults = $query-&gt;result_array();
  
          require (APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel.php');
          require (APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php');
  
          $objPHPExcel = new PHPExcel();
  
          $objPHPExcel-&gt;getProperties()-&gt;setCreator(&quot;&quot;);
          $objPHPExcel-&gt;getProperties()-&gt;setLastModifiedBy(&quot;&quot;);
          $objPHPExcel-&gt;getProperties()-&gt;setSubject(&quot;&quot;);
          $objPHPExcel-&gt;getProperties()-&gt;setCreator(&quot;&quot;);
          $objPHPExcel-&gt;getProperties()-&gt;setDescription(&quot;&quot;);
  
          $objPHPExcel-&gt;setActiveSheetIndex(0);
  
          $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;A1&quot;, 'Event');
          $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;B1&quot;, 'Event Title');
          $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;C1&quot;, 'Event Date');
          $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;D1&quot;, 'Event Start Time');
  
          $objPHPExcel-&gt;getActiveSheet()-&gt;getPageSetup()-&gt;setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
          $objPHPExcel-&gt;getActiveSheet()-&gt;getPageSetup()-&gt;setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
  
          foreach(range('A','D') as $columnID) {
              $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension($columnID)
                  -&gt;setAutoSize(true);
          }
  
          $headerstyle = array(
              'font'  =&gt; array(
              'size'  =&gt; 25,
              'name'  =&gt; 'Candara'
              )
          );
  
          $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A1:D1')-&gt;applyFromArray($headerstyle);
  
  
          foreach (range('A', $objPHPExcel-&gt;getActiveSheet()-&gt;getHighestDataColumn()) as $col) {
              $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension($col)-&gt;setAutoSize(true);
          } 
  
          $excelrow = 2;
  
          foreach ($excelresults as $excelresult =&gt; $excelvalue) {
  
              $columnstyle = array(
                  'font'  =&gt; array(
                  'size'  =&gt;25,
                  'name'  =&gt; 'Candara'
                  )
              );
  
              $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A' . $excelrow . ':D' . $excelrow)-&gt;applyFromArray($columnstyle);
  
  
              $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;A&quot; . $excelrow, $excelvalue['event']);
              $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;B&quot; . $excelrow, $excelvalue['event_title']);
              $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;C&quot; . $excelrow, $excelvalue['event_date']);
              $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue(&quot;D&quot; . $excelrow, $excelvalue['event_start_time']);
  
              $excelrow++;
          }
  
          ///exit();
  
          $filename = 'Bowling-Events-For-' . date('Y') . '.xlsx';
  
          $objPHPExcel-&gt;getProperties()-&gt;setTitle(&quot;Riwaka Bowling Club Events&quot;);
  
          header(&quot;Content-Type: application/vnd.ms-excel; charset=utf-8&quot;); # Important 
          header(&quot;Content-Type: application/force-download&quot;);
          header(&quot;Content-Type: application/octet-stream&quot;);
          header(&quot;Content-Type: application/download&quot;);
  
          header(&quot;Content-Disposition: attachment; filename=&quot;.$filename.&quot;&quot;);
          header(&quot;Content-Transfer-Encoding: binary&quot;);
  
          header(&quot;Pragma: no-cache&quot;);
          
          header(&quot;Expires: 0&quot;);
          
          header(&quot;Cache-Control: must-revalidate, post-check=0, pre-check=0&quot;);
          header(&quot;Cache-Control: private&quot;,false);
  
          $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
          $objWriter-&gt;save('php://output');
  
          exit();
      }
  }
  </code></pre>