This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Blank cells in Excel causing problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Blank cells in Excel causing problems" Watch "Blank cells in Excel causing problems" New topic
Author

Blank cells in Excel causing problems

Matthew Busse
Ranch Hand

Joined: Sep 29, 2010
Posts: 52
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!



Maciej Matiaszowski
Greenhorn

Joined: Aug 14, 2011
Posts: 2

I think that a cell is blank only when it's null. Consider using in case of CELL_TYPE_STRING.
Matthew Busse
Ranch Hand

Joined: Sep 29, 2010
Posts: 52
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!

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Sep 29, 2010
Posts: 52
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:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blank cells in Excel causing problems