Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Import data from XLS and XLSX (Excel) to ADF Table Using Apache POI

Eugen LangJan 16 2023 — edited Jan 16 2023

Hello! I need to add the ability to upload an XLSX file in an existing project. I act according to the instructions http://www.awasthiashish.com/2017/01/import-data-from-xls-and-xlsx-excel-to.html. The question is that when I select an XLSX file, nothing happens. I put the logs inside the uploadFileVCE method, when I upload a file it doesn't output anything, as if it doesn't even enter the method. Help, can anyone come across.

ADF version: Studio Edition Version 12.2.1.0.0
I added jar files:
poi-3.8-beta3
poi-ooxml-3.8-beta3

Here is my jsff file:
upload.png
Here is my Bean class:
log warn.png

Comments

Alex D-Oracle

As an alternative to parsing Excel files, you may want to check out the Oracle Visual Builder Add-in for Excel if the desired business objects have REST API.
https://www.oracle.com/downloads/cloud/visual-builder-addin-downloads.html
This tool allows you to perform bulk updates from Excel with no coding.

Timo Hahn

Have you added the usesUpload="true" property to the af:form of the page?
Only if this property is set the af:inputfile works correctly.

dvohra21

Set uploadType attribute to "auto" or "submit".

samarth_shah

Hi,
You can use this 2 methods to upload both type of Excel files. It is working from my end. Please check it.

Thanks,
Samarth Shah
----------------------------------------------------------------------------------------------------------------------------
public void uploadFileVCE(ActionEvent actionEvent) throws SQLException {
String result_import = null;
try {
result_import = importFileMethod(importFile);
} catch (ParseException e) {
FacesMessage msg = new FacesMessage("Please upload correct file.");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
System.out.println("File imported with :" + result_import);
AdfFacesContext.getCurrentInstance().addPartialTarget(t1);

if ("NO".equalsIgnoreCase(result\_import)) {  
  FacesMessage msg = new FacesMessage("Please upload correct file.");  
  msg.setSeverity(FacesMessage.SEVERITY\_ERROR);  
  FacesContext.getCurrentInstance().addMessage(null, msg);  
}  

}
----------------------------------------------------------------------------------------------------------------------------
private String importFileMethod(UploadedFile importedFile) throws ParseException,
SQLException {
UploadedFile importFile = importedFile;
System.out.println("entered in importFileMethod method");
System.out.println("Value of imported file: " + importFile);
if (importFile == null) {
System.out.println("myfile is null");
resultImport = "NO";
} else {
try {
//Check if file is XLSX
if (importFile.getContentType().equalsIgnoreCase("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ||
importFile.getContentType().equalsIgnoreCase("application/xlsx")) {

      resultImport =  
        readNProcessExcelx(importFile.getInputStream()); //for xlsx  

    }  
    else if (importFile.getContentType().equalsIgnoreCase("application/vnd.ms-excel")) {  

      if (importFile.getFilename().toUpperCase().endsWith(".XLS")) {  
        resultImport =  
          readNProcessExcel(importFile.getInputStream());  
      }  

    }   
    else {  
      FacesMessage msg =  
        new FacesMessage("File format not supported.-- Upload XLSX/XLS file");  
      msg.setSeverity(FacesMessage.SEVERITY\_WARN);  
      FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  
    // AdfFacesContext.getCurrentInstance().addPartialTarget(t1);  
  } catch (IOException e) {  
    FacesMessage msg =  
      new FacesMessage("File format not supported.-- Upload XLS or XLSX file");  
    msg.setSeverity(FacesMessage.SEVERITY\_WARN);  
    FacesContext.getCurrentInstance().addMessage(null, msg);  
  }  
}  
return resultImport;  

}

1 - 4

Post Details

Added on Jan 16 2023
4 comments
613 views