title: Problem in fitting the excel cell size to the size of the content when using apache poi
body: <p>I am beginner to Apache POI api.  I am trying to create  excel sheet using arraylist.  </p>
  
  <p>My java code is as follows.</p>
  
  <pre><code>HSSFWorkbook wb = new HSSFWorkbook();
      HSSFSheet sheet = wb.createSheet("new sheet");
       HSSFCellStyle style = wb.createCellStyle();
          style.setFillForegroundColor(HSSFColor.LIME.index);
          style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  
      HSSFRow row4 = sheet.createRow(4);
      row4.createCell(4).setCellValue("name");
      row4.createCell(5).setCellValue("emailId");
      sheet.autoSizeColumn(5);
      List&lt;Bean&gt; nameList = this.getArrayList();
  
      Iterator&lt;Bean&gt; nameListIterator = nameList.iterator();
  
  
      sheet.autoSizeColumn(5);
  
      int i=5;
      HSSFRow row = null;
  
  
      while(nameListIterator.hasNext())
      {
          Bean bean = nameListIterator.next();
  
          row = sheet.createRow(i);
          row.createCell(4).setCellValue(bean.getName());
  
  
          row.createCell(5).setCellValue(bean.getMailId());
          i++;
      }
  </code></pre>
  
  <p>The arraylist is as follows:</p>
  
  <pre><code>List&lt;Bean&gt; beanList = new ArrayList&lt;Bean&gt;();
      beanList.add(new Bean("Amy","g@y.comrtyrtyrtyrtyrtyr"));
      beanList.add(new Bean("Joan","p@y.comrtyrtyrtyrtyrtyr"));
      beanList.add(new Bean("Megan","r@y.comrtyrtyrtyrtyrtyr"));
      beanList.add(new Bean("Joe","m@y.comrtyrtyrtyrtyrtyr"));
      beanList.add(new Bean("Febi","j@y.comrtyrtyrtyrtyrtyr"));
  </code></pre>
  
  <p>When the excel sheet is generated, the column does not fit to the size of the content correctly.  I searched Google related to this problem and found </p>
  
  <p>sheet.autoSizeColumn(5); </p>
  
  <p>is the solution to my problem.  I added as in the code above, but still the problem persists.  Am I using it correctly?</p>
  
  <p>Is there any other solution?</p>
  
  <p>Please help</p>
  
  <p>Thanks in advance</p>
  
  <p>P.s: I am using Apache Poi 3.6</p>