title: How to populate an Excel sheet with the data from an arraylist using Apache POI
body: <p>How to populate an Excel sheet with the data from an arraylist using Apache POI?</p>
  
  <pre><code>public String exporttoexcel(UserDetails user) throws Exception {
  
      System.out.print("Inside serviceimpl.ExportToExcel method");
      HSSFWorkbook wb = new HSSFWorkbook();
      HSSFSheet sheet = wb.createSheet("new sheet");
      HSSFRow row = sheet.createRow((short)0);
  
          List&lt;UserDetails&gt; lstUserDetail = getUserDetailList();
  
          for (int i=0; i&lt;lstUserDetail.size(); i++) {
  
              UserDetails lstUserDetail1 = lstUserDetail.get(i);
  
              String a=lstUserDetail1.getStrUserName();
               System.out.print("useridddd is"+a);
  
               HSSFCell cell = row.createCell((short) 0);
                  cell.setCellValue(lstUserDetail1.getStrUserId());
                  cell.setCellValue(lstUserDetail1.getStrUserName());
                  cell.setCellValue(lstUserDetail1.getStrEMail());
                  cell.setCellValue(lstUserDetail1.getStrUserStatus());
                  cell.setCellValue(lstUserDetail1.getStrUserRole());
  
           }
           FileOutputStream fileOut = new FileOutputStream("workbook.xls");
          wb.write(fileOut);
          fileOut.close();
  
         System.out.print("file created");
  
         return null;
          }
  </code></pre>