File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read Excel Sheet

 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to read the excel sheet. I've used POI library.


I'm getting null pointer exception at in for loop.

I want to display all contents from excel sheet.
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you're getting the NPE in the for loop? If anything, I would expect an NPE way back on Line 4 before you'd get one on Line 10. Is that a complete listing or did you omit some code in between Line 4 and Line 10?
 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line 4 not returning NPE. Now i found that the excel sheet I'm reading has first 3 rows empty. so it is returning NPE at line 10. How to read the remaining rows?
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaDocs say that getRow returns null if the row is not defined. Are you sure that the NPE is thrown on Line 10 and not Line 11? That's where the NPE would be thrown if getRow(i) returns null.
 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My mistake, getCell() method is returning NPE... well then how I'm i supposed to get further rows even if there is an empty row in the middle.
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



this might help...
 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome To Ranch buddy
Well sheet.getColumns() and sheet.getRows() are in JXL library... I want to do it in Apache's POI library..
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad Rooge wrote:Welcome To Ranch buddy
Well sheet.getColumns() and sheet.getRows() are in JXL library... I want to do it in Apache's POI library..


....ok let me read your query again then...
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the static class Row.MissingCellPolicy



and pass Row.RETURN_NULL_AND_BLANK in the policy parameter
which will have missing cells returned as null, Blank cells returned as normal

was this helpful??
 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
had seen it in documentation and tried but same exception...

 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


try this




tell me if this works or not..
 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First i dont know what will that return.. second dont know where do you want me to try it.
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad Rooge wrote:First i dont know what will that return.. second dont know where do you want me to try it.


in your console output...
am i getting you right...your getCell() is throwing an NPE...



it just checks for the null you are getting in form of blanks. if null then print "" otherwise get the value..
 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya getCell() is throwing an NPE... but even before i check for that condition it is throwing exception.. may be there is some other way to proceed..
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad Rooge wrote:My mistake, getCell() method is returning NPE... well then how I'm i supposed to get further rows even if there is an empty row in the middle.

Am I missing something ? Why don't you just check if row is null before you use it
 
Prasad Rooge
Greenhorn
Posts: 25
Firefox Browser Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got that right... damn its so simple
 
Ankit Dan
Ranch Hand
Posts: 47
Eclipse IDE Java MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad Rooge wrote: You got that right... damn its so simple
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic