• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to parse an Excel sheet and get the data

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai
I have this requirement of parsing an excel sheet and getting the data in it and storing the data in the appropriate tables in database.Please suggest me some way of doing this or the links wherein ican get some solution.
Thanks in advance.........
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Libraries like POI and jExcelAPI can read XLS files. You'll find links to these in the AccessingFileFormats page.
 
kranthi chamarthi
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that link.
I have downloaded the zip files ,set the classpath of the jar files.
I compiled the code .It compiled successfully.But when running,i got "UnsupportedClassVersionError"

Following is the code
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import java.io.FileInputStream;
/**
* This is a sample to Read an Excel Sheet using
* Jakarta POI API
* @author Elango Sundaram
* @version 1.0
*/
public class ReadXL {
/** Location where the Excel has to be read from. Note the forward Slash */
public static String fileToBeRead="C:/Documents and Settings/induction/Desktop/jw-0322-poi/Read.xls";
public static void main(String argv[]){
try{
// Create a work book reference
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(fileToBeRead));
// Refer to the sheet. Put the Name of the sheet to be referred from
// Alternative you can also refer the sheet by index using getSheetAt(int index)
HSSFSheet sheet = workbook.getSheet("Sheet1");
//Reading the TOP LEFT CELL
HSSFRow row = sheet.getRow(0);
// Create a cell ate index zero ( Top Left)
HSSFCell cell = row.getCell((short)0);
// Type the content
System.out.println("THE TOP LEFT CELL--> " + cell.getStringCellValue());

}catch(Exception e) {
System.out.println("!! Bang !! xlRead() : " + e );
}

}

}
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kranthi,

You're probably using a jar that was compiles with jdk 1.5+, and your jvm version is probably 1.4+. Check the manifest of the jar file, then check your JVM version(java -version). That'll get to started.

Chances are pretty good that you'll be able to find a compatible version of the jar is you search the site Ulf gave you.

good luck!
M
 
kranthi chamarthi
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked.There is a problem with my jre.
reply
    Bookmark Topic Watch Topic
  • New Topic