Note that there are some explanatory texts on larger screens.

plurals
  1. PORead the Excel value using JSF
    primarykey
    data
    text
    <p>I need to read an Excel file and display its content. I have a backing bean code which reads a particular Excel file and displays its content in the console. I have to display the contents inside a text editor. Using PrimeFaces I have got the <code>&lt;p:fileUpload&gt;</code> and <code>&lt;p:editor&gt;</code>. </p> <p>Here's the bean: </p> <pre><code>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("")); // 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&lt;Row&gt; rowIterator = sheet.rowIterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); // For each row, iterate through each columns Iterator&lt;Cell&gt; 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"); } } </code></pre> <p>Here's the Facelet:</p> <pre><code>&lt;h:body&gt; &lt;h:form enctype="multipart/form-data"&gt; &lt;p:fileUpload fileUploadListener="#{uploadBean.handleFileUpload}" mode="advanced" update="display" auto="true" sizeLimit="10000000" allowTypes="/(\.|\/)(xls|xlsx)$/" /&gt; &lt;p:growl id="display" showDetail="true" /&gt; &lt;h:commandButton action="#{uploadBean.convertjava}" value="Excel Report" /&gt; &lt;/h:form&gt; &lt;br /&gt; &lt;/h:body&gt; </code></pre> <p>Here I am totally blank that how to call that <code>convertJava()</code> method through JSF tags and display the read excel values inside an text editor. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload