简体   繁体   English

在jsf中从excel导入有组织的表

[英]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. 我有一个包含6行和31列的excel表,我想将其导入到我的jsf页面。 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. 我成功地在控制台中按顺序显示了它,但是我找不到在jsf页面中执行相同操作的方法。

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. 首先,您可以定义一个名为Foo的类,该类具有与excel文件相同的属性。 Then instead of writing to the console you can instantiate an object of Foo class and add it to a List . 然后,您可以实例化Foo类的对象并将其添加到List而无需写入控制台。 Finally you can use jsf to show values in the List using some code like this: 最后,您可以使用jsf使用类似以下代码的代码在List显示值:

<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/ 以下类似内容可能会帮助您如何使用jsf显示数据: https : //www.mkyong.com/jsf2/jsf-2-datatable-example/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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