简体   繁体   中英

Import an organised table from excel in jsf

I have an excel table with 6 rows and 31 columns and i want to import it to my jsf page. I succeeded to display it in order in the console but i couldn't find a way to do the same in my jsf page.

This is the code:

public void showfile() throws FileNotFoundException,IOException{

    FileInputStream fis= new FileInputStream("C:\\Users\\tahab_000\\Desktop\\Test.xls");
    HSSFWorkbook wb=new HSSFWorkbook(fis);
    HSSFSheet sheet=wb.getSheetAt(0);
    FormulaEvaluator formulaEvaluator=wb.getCreationHelper().createFormulaEvaluator();

    for(Row row: sheet){
        for(Cell cell: row){
            switch(formulaEvaluator.evaluateInCell(cell).getCellType()){
            case Cell.CELL_TYPE_NUMERIC:
                System.out.print(cell.getNumericCellValue()+"\t\t");
                s1=s1+cell.getNumericCellValue();
                break;
            case Cell.CELL_TYPE_STRING:
                System.out.print(cell.getStringCellValue()+"\t\t");
                s1=s1+cell.getStringCellValue();
                break;

            }
        }
        System.out.println();
    }
}

First of all, you can define a Class named Foo which has same properties as your excel file do. Then instead of writing to the console you can instantiate an object of Foo class and add it to a List . Finally you can use jsf to show values in the List using some code like this:

<h:dataTable value="#{beanName.yourList} ..../>"

the following like might help you to how to show a data with jsf: https://www.mkyong.com/jsf2/jsf-2-datatable-example/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM