• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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!

 
Saloon Keeper
Posts: 7633
177
  • 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:

 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic