Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read data from ExcelSheet

 
saravana kumar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I want to read data from Excel sheet and save into database.how can i do that? anyone can please let me know how to do that? if any one have code means please send me to saranindia@hotmail.com.

Thanks lot.
Regards
saran
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try formula1. (former tidestone,now actuate)
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading Excel is just like accessing a database.
Do a search on Excel in the JDBC forum and you will get LOTS of info.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see the article/tutorial called It's Excel-lent: Read MS Excel files with Java written by javaworld.com. To learn how to use JDBC see Sun's Tutorial on JDBC.
Jamie
 
Antonio Goodman
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 saravana kumar
---------------------------
hi, i solve the same problem, yes if you have xls document whith one sheet - then : http://www.javaworld.com/javaworld/javaqa/2002-05/01-qa-0503-excel3.html (It should help you),
but another problem whem you have many sheets
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jamie
[ October 09, 2002: Message edited by: Jamie Robertson ]
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Export your data to Comma Separated Value (CSV) format and use libraries to read and write this format:
http://ostermiller.org/utils/ExcelCSV.html
Use excelread by Andy Khan to get excel data into your java program:
http://www.andykhan.com/excelread/
The apache project has a library which called POI that can read and write the HSSF (Horrible Spread Sheet Format) that excel uses.
http://jakarta.apache.org/poi/hssf/
Connect to an Excel spreadsheet file using jdbc.
http://www.jguru.com/faq/view.jsp?EID=32876
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read:
http://jinx.swiki.net/324
 
Zoltan Rajcsanyi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
SR
My program summarizes the values.
The output will be:
Rows: 6
Cols: 6
Result: 16
-------------------------------------
import java.io.*;
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);
workbook.close();
} catch (IOException e) {
System.err.print("I/O error.");
System.exit(0);
} catch (jxl.read.biff.BiffException e) {
System.err.print("Corrupt file or an another program use the XLS.");
System.exit(0);
}
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic