title: PHPExcel How to apply styles and set cell width and cell height to cell generated dynamically
body: <p>I have form that I generate its content to Excel through PHPExcel, my problem is that 
  how can I set width and height and also styles to the heading cells.</p>
  
  <p>the excel generated demo is here:</p>
  
  <p><img src="https://i.stack.imgur.com/mNHAY.png" alt="enter image description here"></p>
  
  <p>the excel i want is here:
  <img src="https://i.stack.imgur.com/sXTLz.png" alt="enter image description here"></p>
  
  <p>here is my code:</p>
  
  <pre><code>for ($col = 'A'; $col != 'J'; $col++) {
         $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension($col)-&gt;setAutoSize(true);
                  }
  
                  $objPHPExcel-&gt;getProperties()-&gt;setCreator("HOO")
                                                          -&gt;setLastModifiedBy("HOO")
                                                          -&gt;setTitle("Jobs History")
                                                          -&gt;setSubject("PHPExcel Test Document")
                                                          -&gt;setDescription("Test document for PHPExcel, generated using PHP classes.")
                                                          -&gt;setKeywords("office PHPExcel php")
                                                          -&gt;setCategory("Test result file");
  
                  $objPHPExcel-&gt;setActiveSheetIndex(0)-&gt;mergeCells('A1:I1');
                  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A1', $this-&gt;lang-&gt;line('history_excel_title'));
                  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle("A1")-&gt;getFont()-&gt;setBold(true);
  
                  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A2:I2')-&gt;getFill()-&gt;setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A2:I2')-&gt;getFill()-&gt;getStartColor()-&gt;setARGB('29bb04');
                  // Add some data
                  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle("A2:I2")-&gt;getFont()-&gt;setBold(true);
                  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A2:I2')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
  
  
                  //echo date('H:i:s') , " Add some data" , EOL;
                  $objPHPExcel-&gt;setActiveSheetIndex(0)
                              -&gt;setCellValue('A2', $this-&gt;lang-&gt;line('global_no'))
                              -&gt;setCellValue('B2', $this-&gt;lang-&gt;line('history_name'))
                              -&gt;setCellValue('C2', $this-&gt;lang-&gt;line('history_type_emp'))
                              -&gt;setCellValue('D2', $this-&gt;lang-&gt;line('history_job_title'))
                              -&gt;setCellValue('E2', $this-&gt;lang-&gt;line('history_emp_date'))
                              -&gt;setCellValue('F2', $this-&gt;lang-&gt;line('history_emp_duration'))
                              -&gt;setCellValue('G2', $this-&gt;lang-&gt;line('history_duty'))
                              -&gt;setCellValue('H2', $this-&gt;lang-&gt;line('history_contact_duty'))
                              -&gt;setCellValue('I2', $this-&gt;lang-&gt;line('history_salary'));
  
                  $objPHPExcel-&gt;getActiveSheet()-&gt;getRowDimension(1)-&gt;setRowHeight(-1);
  
                  $i =3;
                  foreach($details-&gt;result() AS $item)
                  {
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('B'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('C'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('D'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('E'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('F'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('G'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('H'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('I'.$i.'')-&gt;getBorders()-&gt;getAllBorders()-&gt;setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
                      // Miscellaneous glyphs, UTF-8
                      $objPHPExcel-&gt;setActiveSheetIndex(0)
                              -&gt;setCellValue('A'.$i, $i-2)
                              -&gt;setCellValue('B'.$i, $item-&gt;employer_office)
                              -&gt;setCellValue('C'.$i, $item-&gt;job_type)
                              -&gt;setCellValue('D'.$i, $item-&gt;job_title)
                              -&gt;setCellValue('E'.$i, $item-&gt;job_appointment_date)
                              -&gt;setCellValue('F'.$i, $item-&gt;job_duration)
                              -&gt;setCellValue('G'.$i, $item-&gt;job_place)
                              -&gt;setCellValue('H'.$i, $item-&gt;type_of_relation)
                              -&gt;setCellValue('I'.$i, $item-&gt;monthly_salary);
                      $i++;
                  }
  </code></pre>