How to read data from excel sheet using JEXcel:
=====================================
JExcel is free API to work with Excel files;
Basically api is an collection of predefined classes and interfaces...
Following are the regularly used classes and interfaces to read data
Workbook (Class) – Will handle workbook.
Sheet (Interface) – Which will handle sheets
Cell (Interface) – Which will handle cell
Download JExcel API:
----------------------
OPEN GOOGLE-->DOWNLOAD JXCEL API
OR
http://mirrors.ibiblio.org/pub/mirrors/maven/net.sourceforge.jexcelapi/jars/jxl-2.6.jar
AFTER DOWNLOADING ADD THAT JXCEL JAR FILE IN TO YOUR PROJECT.
//Sample program on how to read data from jexcel
-----------------------------------------------------
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.testng.annotations.Test;
public class JexcelRead {
@Test
public void readData() {
File src=new File("./data/testdata.xls");
try {
Workbook workBook = Workbook.getWorkbook(src);
Sheet sheet= workBook.getSheet(0);
Cell cell = sheet.getCell(0,0);
String cellData=cell.getContents();
System.out.println(cellData);
System.out.println("Sheet data is "+cellData);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
=====================================
JExcel is free API to work with Excel files;
Basically api is an collection of predefined classes and interfaces...
Following are the regularly used classes and interfaces to read data
Workbook (Class) – Will handle workbook.
Sheet (Interface) – Which will handle sheets
Cell (Interface) – Which will handle cell
Download JExcel API:
----------------------
OPEN GOOGLE-->DOWNLOAD JXCEL API
OR
http://mirrors.ibiblio.org/pub/mirrors/maven/net.sourceforge.jexcelapi/jars/jxl-2.6.jar
AFTER DOWNLOADING ADD THAT JXCEL JAR FILE IN TO YOUR PROJECT.
//Sample program on how to read data from jexcel
-----------------------------------------------------
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.testng.annotations.Test;
public class JexcelRead {
@Test
public void readData() {
File src=new File("./data/testdata.xls");
try {
Workbook workBook = Workbook.getWorkbook(src);
Sheet sheet= workBook.getSheet(0);
Cell cell = sheet.getCell(0,0);
String cellData=cell.getContents();
System.out.println(cellData);
System.out.println("Sheet data is "+cellData);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Note:If you want APACHE API please refer our previous posts in my blog
No comments:
Post a Comment