File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Read data from ExcelSheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Read data from ExcelSheet" Watch "Read data from ExcelSheet" New topic

Read data from ExcelSheet

saravana kumar
Ranch Hand

Joined: Jun 25, 2002
Posts: 72
Hi Friends,
I want to read data from Excel sheet and save into can i do that? anyone can please let me know how to do that? if any one have code means please send me to

Thanks lot.
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
theres a few API's available to do that, you can try Jakarta's POI, which i haven't tried yet but i have used JExcelAPI, you'll find a link to it from POI's alternatives page but that link never works, try google search for it, it definately moved, sorry i cant find the right link anywhere in the jar i have, the docs dont say, and normally looking at package in source helps but not this time, if you want i'll mail the jar to you, drop a pvt msg else i'll try drop by here again later today
Jakarta POI Alternatives
[ October 02, 2002: Message edited by: Taariq Levack ]
Aleksey Matiychenko
Ranch Hand

Joined: Apr 03, 2001
Posts: 178
try formula1. (former tidestone,now actuate)
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Reading Excel is just like accessing a database.
Do a search on Excel in the JDBC forum and you will get LOTS of info.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

see the article/tutorial called It's Excel-lent: Read MS Excel files with Java written by To learn how to use JDBC see Sun's Tutorial on JDBC.
Antonio Goodman

Joined: Oct 01, 2002
Posts: 19
2 saravana kumar
hi, i solve the same problem, yes if you have xls document whith one sheet - then : (It should help you),
but another problem whem you have many sheets
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

[ October 09, 2002: Message edited by: Jamie Robertson ]
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
Export your data to Comma Separated Value (CSV) format and use libraries to read and write this format:
Use excelread by Andy Khan to get excel data into your java program:
The apache project has a library which called POI that can read and write the HSSF (Horrible Spread Sheet Format) that excel uses.
Connect to an Excel spreadsheet file using jdbc.
Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
Please read:
Zoltan Rajcsanyi

Joined: Feb 18, 2003
Posts: 3
Hi Friends!
I thing this code is usefull for you. I try the jax and it seems to easy to use. I created an excel file with a coloumn header, a row header, a row summary and a coloumn summary line. So ... For example:
test.xls contains that above:
B1 C1 D1 E1 SC
A2 1 1 1 1
A3 1 1 1 1
A3 1 1 1 1
A4 1 1 1 1
My program summarizes the values.
The output will be:
Rows: 6
Cols: 6
Result: 16
import java.util.Date;
import jxl.*;
public class ImportXLS {
public static void main(String args[]) {
Workbook workbook;
File file;
Cell cel;
String str = "";
long lngSumm;

String strXLSFilename = "d:\\java\\programs\\test.xls";
System.out.println("filename: " + strXLSFilename);

try {
file = new File(strXLSFilename);
workbook = Workbook.getWorkbook(file);
Sheet sheet = workbook.getSheet(0);

lngSumm = 0;

System.out.println("columns:" + sheet.getColumns());
System.out.println("rows: " + sheet.getRows());

for (int a = 1; a < sheet.getColumns()-1; a++) {
for (int b = 1; b < sheet.getRows()-1; b++) {
cel = sheet.getCell(a,b);
str = cel.getContents();
try {
lngSumm += Double.valueOf(str).doubleValue();
} catch (Exception e) {
System.err.println("Error: " + e);
System.out.println("result: " + lngSumm);
} catch (IOException e) {
System.err.print("I/O error.");
} catch ( e) {
System.err.print("Corrupt file or an another program use the XLS.");
I agree. Here's the link:
subject: Read data from ExcelSheet
It's not a secret anymore!