Skip to Main Content

Reading a Excel value using JSF

1020413Jun 27 2013

Hello all,

I have an Backing bean which reads the Excel values and Display it in Console. The same I have to integrate with JSF as an Web application and I have to Display the contents by using JSF tags. Can Anyone help meby giving the basic Idea about this?

The Backing Bean is

public void handleFileUpload(FileUploadEvent event) {
       
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
       
FacesContext.getCurrentInstance().addMessage(null, msg);
   
}
   
public String convertjava(String b) {
   
try
   
{
   
FileInputStream file = new FileInputStream(new File("C://demo.xls"));
           
// Get the workbook instance for XLS file
           
HSSFWorkbook workbook = new HSSFWorkbook(file);
           
// Get first sheet from the workbook
           
HSSFSheet sheet = workbook.getSheetAt(0);
           
// Iterate through each rows from first sheet
           
Iterator<Row> rowIterator = sheet.rowIterator();
           
while (rowIterator.hasNext()) {
               
Row row = rowIterator.next();
               
// For each row, iterate through each columns
               
Iterator<Cell> cellIterator = row.cellIterator();
               
while (cellIterator.hasNext()) {
                   
Cell cell = cellIterator.next();
                   
switch (cell.getCellType()) {
                   
case Cell.CELL_TYPE_BOOLEAN:
                        cell
.getBooleanCellValue();
                       
break;
                   
case Cell.CELL_TYPE_NUMERIC:
                        cell
.getNumericCellValue();
                       
break;
                   
case Cell.CELL_TYPE_STRING:
                        cell
.getStringCellValue();
                       
break;
                   
}
               
}
               
System.out.println("");
           
}
            file
.close();
           
FileOutputStream out = new FileOutputStream(new File(""));
            workbook
.write(out);
           
out.close();

       
} catch (FileNotFoundException e) {
            e
.printStackTrace();
       
} catch (IOException e) {
           
System.out.println("error");
       
}
       
}

Can Anyone help me in acheiving this through JSF tags??

Comments
Post Details
Added on Jun 27 2013
0 comments
1,774 views