简体   繁体   English

使用 Apache POI 将数据从 XLS 和 XLSX (Excel) 导入 ADF 表

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

I need to add the ability to upload an XLSX file in an existing project.我需要添加在现有项目中上传 XLSX 文件的功能。 I act according to the instructions http://www.awasthiashish.com/2017/01/import-data-from-xls-and-xlsx-excel-to.html .我按照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.问题是,当我 select 一个 XLSX 文件时,没有任何反应。 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.我将日志放在 uploadFileVCE 方法中,当我上传文件时它没有 output 任何东西,就好像它甚至没有进入该方法一样。 Help, can anyone come across.求助,谁能遇到。

ADF version: Studio Edition Version 12.2.1.0.0 ADF 版本:Studio Edition Version 12.2.1.0.0

Here is my jsff file:这是我的 jsff 文件:

<af:inputFile label="Upload file" id="if1"
valueChangeListener="#{pageFlowScope.Class1Bean.uploadFileVCE}"
autoSubmit="true" 
labelStyle="font-weight:bold;color:navy;"/>

here is my Bean class:这是我的 Bean class:

 public void uploadFileVCE(ValueChangeEvent valueChangeEvent) {
        log.warn("FIRST");
            UploadedFile file = (UploadedFile) valueChangeEvent.getNewValue();
            log.warn("SECOND");
            try {
                //Check if file is XLSX
                log.warn("THIRD");
                if (file.getContentType().equalsIgnoreCase("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ||
                    file.getContentType().equalsIgnoreCase("application/xlsx")) {
                    log.warn("FOURTH");
                    readNProcessExcelx(file.getInputStream()); //for xlsx

                }
                //Check if file is XLS
                else if (file.getContentType().equalsIgnoreCase("application/vnd.ms-excel")) {

                    if (file.getFilename().toUpperCase().endsWith(".XLS")) {
                       // readNProcessExcel(file.getInputStream()); //for xls
                    }

                } else {
                    FacesMessage msg = new FacesMessage("File format not supported.-- Upload XLS or XLSX file");
                    msg.setSeverity(FacesMessage.SEVERITY_WARN);
                    FacesContext.getCurrentInstance().addMessage(null, msg);
                }
                AdfFacesContext.getCurrentInstance().addPartialTarget(empTable);

            } catch (Exception e) {
                log.warn(e);
            }
        }

The solution to this problem is to add a parameter usesUpload="true" .这个问题的解决方案是添加一个参数usesUpload="true" I have this form <af:form was set in another.jsff file, so I added the usesUpload="true" parameter to the file where the form was located.我有这个表单<af:form是在另一个.jsff 文件中设置的,所以我将usesUpload="true"参数添加到表单所在的文件中。

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

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