• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Blank cells in Excel causing problems

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm trying to use Apache POI to read an excel file, then copy it to a new file with some extra information added, specifically, information about the types of data in the excel sheet. It's almost working, but I'm having problems with blank cells, my program doesn't seem to recognize them. I tried adding a case (line 61) to specifically act on blank cells. And even if that doesn't work, I would expect default to catch anything else, but neither solution is able to recognize a blank cell and insert "unknown" into the HashMap. Any ideas?

Thanks!



 
Greenhorn
Posts: 2
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that a cell is blank only when it's null. Consider using in case of CELL_TYPE_STRING.
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help. Alas, that didn't work. I added a println, to check what's going on, it doesn't seem like the blank cell is being recognized as a string or number case, so I still don't understand why the default isn't catching it?

Thanks!

 
Bartender
Posts: 7493
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to ask the obvious: you've ascertained that "(cell != null)" is true, in other words, that "cell" is not null? If so, what value does "sourceCellValue.getCellType()" have?
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Just to ask the obvious: you've ascertained that "(cell != null)" is true, in other words, that "cell" is not null? If so, what value does "sourceCellValue.getCellType()" have?



Aha! That was the problem. The blank cell is null, not Cell_Type_Blank. (Which leads me to wonder when Cell_Type_Blank comes into play. But that's a different question)
I added an else statement to handle the case when cell != null is false.

Thanks!

Here's the revised code, for the benefit of future readers:

 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic