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: 16479
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: 35220
posted Apr 07, 2009 15:59:40
0
So JExcelApi can't deal with it - that doesn't mean that POI can't deal with it, either.
Android apps – ImageJ plugins – Java web charts
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: 35220
posted Apr 08, 2009 08:31:12
0
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: 35220
posted Apr 08, 2009 08:41:17
0
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: 19214
You never initialize a1, so you are trying to put something into null.
SCJP 1.4 - SCJP 6 - SCWCD 5
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: 19214
But you can't access (read, write) any array element if that array reference is null. You must first initialize the Cell array:
subject: accessing excel file from java