Step 1 : Load the data to a object of type List
Step 2 : Iterate the list of the object and write the data corresponding to the excel file...
Step 3 : upload the data..
Code Snippet...
String fileName = "excelFileName";
// Create a new work book
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("mySheet1");
........
..........
........
for (SlectedObjectTO : objectList)
{
HSSFRow rows = sheet.createRow(j);
..........
........
}
// Writing data to the output stream.
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
.getResponse();
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xls");
response.setContentType("application/vnd.ms-excel");
log.debug("Response contect :: " + response.getContentType());
ServletOutputStream out;
try
{
out = response.getOutputStream();
wb.write(out);
out.flush();
out.close();
}
Required API :: POI