我收到错误java.lang.NumberFormatException:对于输入字符串:Excel

时间:2015-04-07 07:36:59

标签: java excel oracle

使用Jdeveloper 12C,Oracle DB 12C,Windows 8.1 这是我将Excel文件读取到DB的代码。

这是代码I

的图像

link to the code

FileInputStream file = new FileInputStream
    (new File("E:/Company Mails.xlsx"));
     XSSFWorkbook workbook = new XSSFWorkbook(file);   
        XSSFSheet sheet = workbook.getSheetAt(0);    
        Iterator<Row> rowIterator = sheet.iterator();          
        DCBindingContainer bindings2 = (DCBindingContainer) 
        BindingContext.getCurrent().getCurrentBindingsEntry();
        JUCtrlHierBinding obj = (JUCtrlHierBinding) 
        bindings2.findCtrlBinding("CompanyMails1");
        ViewObject vo = obj.getViewObject();            
        BindingContainer bindings = BindingContext.
        getCurrent().getCurrentBindingsEntry();
        OperationBinding operationBinding = bindings.
        getOperationBinding("Commit");                            
                while (rowIterator.hasNext()){                        
                    Row row = rowIterator.next(); 
                    Iterator<Cell> cellIterator = row.cellIterator();
                    oracle.jbo.Row r = vo.createRow();                        
                    while (cellIterator.hasNext()){
                        Cell cell = cellIterator.next();
                        r.setAttribute("No", row.getCell(0));
                        r.setAttribute("Mail", row.getCell(1));
                        r.setAttribute("Person", row.getCell(2));} }
                file.close(); operationBinding.execute();}
            catch (Exception e){e.printStackTrace(); }
    return null;} 

这是我在Jdev上得到的消息

<org.apache.myfaces.trinidad.component.UIXComponentBase> <UIXComponentBase> <getClientId> <INVALID_CALL_TO_GETCLIENTID>  <oracle.adf.controller> <Utils> <buildFacesMessage> <ADF: Adding the following JSF error message: For input string: "No">  java.lang.NumberFormatException: For input string: "No"     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)

&#34;否&#34;因为String是Excel文件中第一列的头部 这是运行代码后出现的错误的图片。

link to the error i got on the browser

1 个答案:

答案 0 :(得分:0)

setAttribute()方法需要列的索引。不是列标题。 所以你必须改为:

r.setAttribute(0, row.getCell(0));