2016-09-20 28 views
0

我有一個Excel表格,包含6行和31列,我想將它導入到我的jsf頁面。我成功地在控制檯中顯示它,但我找不到在我的jsf頁面中執行相同操作的方法。從jsf中導入excel中有組織的表格

這是代碼:

所有的
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(); 
    } 
} 

回答

0

首先,你可以定義一個名爲Foo類作爲您的Excel文件來執行它具有相同的屬性。然後,不要寫入控制檯,而是可以實例化Foo類的對象,並將其添加到List。最後,你可以使用JSF使用像這樣的代碼顯示在List值:

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

以下類似可以幫助你如何顯示與JSF數據: https://www.mkyong.com/jsf2/jsf-2-datatable-example/