I am trying to read an excel file with words and not numeric data using the code from apache site http://poi.apache.org/spreadsheet/how-to.html#xssf_sax_api
I get the following error:
Processing new sheet:
A1 - Have a nice day
Exception in thread "main" java.lang.NumberFormatException: For input string: "Have a nice day"
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1111)
at ExcelExtract.processAllSheets(ExcelExtract.java:48)
at ExcelExtract.main(ExcelExtract.java:119)
Caused by: java.lang.NumberFormatException: For input string: "Have a nice day"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at ExcelExtract$SheetHandler.endElement(ExcelExtract.java:99)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1550)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1204)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
开发者_高级运维 ... 2 more
Also is there any way to read xlsx file using poi xssf event model only without using xerces.jar? Please inform if any other sample code is available.
That exception seems to be coming from your own code - ExcelExtract looks to be your program rather than a core bit of POI
It looks like you're treating a cell that contains a string as if it contains a number. That won't work - you need to check the type of the cell, and handle the contents appropriately. You can't just parse something to an int without first ensuring it is one!
Doesn't look to be a POI issue though
精彩评论