title: Generate excel file using java with different column width
body: <p>I am doing a java application (J2SE) which I have to generate a excel document (.xls). I did generate the file but I am not able to change the cell width dynamically according to the content which is having the maximum length in the same cell.  </p>
  
  <p>Here is my coding...  </p>
  
  <pre><code>     try {
  
        ResultSet rs = com.dss.system.DBORCL.search("sql statement");
  
          HSSFWorkbook wb = new HSSFWorkbook();
          HSSFSheet sheet = wb.createSheet("Excel Sheet");
          HSSFRow rowhead = sheet.createRow((short) 0);
  
          rowhead.createCell((short) 0).setCellValue("Site");
          rowhead.createCell((short) 1).setCellValue("Part No");
          rowhead.createCell((short) 2).setCellValue("Part Description");
          int index = 1;
          while (rs.next()) {
  
              HSSFRow row = sheet.createRow((short) index);
  
              row.createCell((short) 0).setCellValue(rs.getString("site"));
              row.createCell((short) 1).setCellValue(rs.getString("part_no"));
              row.createCell((short) 1).setCellValue(rs.getString("description"));
              index++;
              }           
  
  
          FileOutputStream fileOut = new FileOutputStream("F:\\IFS\\IFSDOC" +    txtPLCode.getText() + "[" + currentDate + "-" + usesecond + "]" + ".xls");
          wb.write(fileOut);
          fileOut.close();
          System.out.println("Data is saved in excel file.");
          //  rs.close();
  </code></pre>