aspose file tools*
The moose likes Other Open Source Projects and the fly likes accessing excel file from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "accessing excel file from java" Watch "accessing excel file from java" New topic
Author

accessing excel file from java

baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
can any one tell me how to code in java so that i can access the excel sheet and do manipulations in the specific column

say if i have to read the data from the column 7 in excel sheet and find the average of the 7th column
is that possible to do

please help me
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Bharadwaz,

Check out Apache POI
baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
hmm yea i have seen those files and tried to get the result from it but my case is different i am not creating the excel file now

i have the file and i need to retrive the columns of the file and find the average of the particular column
could it be done
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

Your case is different than what? You can certainly use Apache POI to read Excel documents and extract data from them, I have done it myself. That's your requirement too.
baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
oh im sorry i forgot to mention it

the excel file i am trying to load is of about 26 mb with over 3lakh lines and it raises the exception to load that file
i thought i mentioned it

i get ::::: jxl.read.biff.BiffException: Unable to recognize OLE stream exception when i run the code


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
So JExcelApi can't deal with it - that doesn't mean that POI can't deal with it, either.


Ping & DNS - updated with new look and Ping home screen widget
baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
yea i even tried it with POI package and now i get another exception saying

::::: java.io.IOException: Invalid header signature; read 1688935826934608, expected -2226271756974174256



Moojid Hamid
Ranch Hand

Joined: Mar 07, 2009
Posts: 120
If I am not mistaken you are using Excel 2007. Support for that format is still in beta. Try POI 3.5 beta 5 according to POI webpage.
baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
ya now i get the values out


but is there a way to store the values which are retrieved from excel sheet into an array
so that i can sort them

when i try to bring an array on

it says :::::::: Exception in thread "main" java.lang.NullPointerException


i used this part for it

Cell a1[]=null;
try
{
workbook=jxl.Workbook.getWorkbook(f);
for(int i=0;i<30;i++){
sheet=workbook.getSheet(0);
a1[i]= sheet.getCell(6,i);
System.out.println(a1[i].getContents());

}
workbook.close();
}catch(IOException ex){

and if i wont initialize the array i get an error saying not initialized.....

what can i do now
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
The first step is to find out which object that you are dereferencing is null.
baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
the line
a1[i]= sheet.getCell(6,i);


is giving null exception
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Assuming that "sheet" is null, you now need to find out why the "getSheet" method returns a null object.
baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
actually if i wont use array there i get the result

but when i make array then i get null exception
i have checked it first initializing sheet to null and cell to null
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

You never initialize a1, so you are trying to put something into null.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
baaru so
Greenhorn

Joined: Apr 02, 2008
Posts: 25
a1 is of type Cell
and i want to parse the values of a1 to some array a of type integer and do sorting cal mx and min values

i initialized the array cell a1 to null first
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

But you can't access (read, write) any array element if that array reference is null. You must first initialize the Cell array:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing excel file from java
 
Similar Threads
Reading data from Excel Sheets
java
. reading data from MS EXcel using apache poi api
read data from excel sheet and put it into the postgresql database
Reading Data from Excel Sheets