This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Number Format in Apache poi api  RSS feed

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am using apache poi api to read data from the excel file and having problem with particular data format.

One of the coumns in the excel file had formula type whose value will be in the below format

"2001-160101100-22110-0000-000"

Note : the no of digits between each dash and the number of dash itself may vary but the format will always be numbers followed by - and end with numbers.

The api successfully find the field type as formula and consider it as numeric type but it throws NumberFormatException as it contains -.

I am using DataFormat class to read all the numeric cell value as we need to read the data as it is (no round up or truncate) in the cell value.

I was going through the genral format available in the api but could not understand how to add custom format to the list of available formats.
I was trying to use DataFormat.addFormat(String,Format) from the api but did not understand what to pass in the String argument and how to define the Format for this custom format.

Your help is appreciated.



java.lang.NumberFormatException: For input string: "2001-160101100-22110-0000-000"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1207)
at java.lang.Double.parseDouble(Double.java:220)
at org.apache.poi.xssf.usermodel.XSSFCell.getNumericCellValue(XSSFCell.java:197)
at org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(DateUtil.java:278)
at com.excel.reader.ExcelDataReader.isNumberOrDate(ExcelDataReader.java:166)
at com.excel.reader.ExcelDataReader.getCellValue(ExcelDataReader.java:154)
at com.excel.reader.ExcelDataReader.process(ExcelDataReader.java:118)
at com.excel.reader.ExcelDataReader.main(ExcelDataReader.java:249)
Exception in thread "main" ACBS 2001 7528080 Java Result: 1

 
get schwifty. tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!