Header Ad

Thursday, January 17, 2008

Reading XLS Content Using Java Code.

Reading XLS Content Using Java Code.

We can read XLS content cell by cell by using java code.For this we need jxl jar file.

The following is the simple example to read .xls file and display its content.

Following is the link to download jxl jar file
http://fisheye1.cenqua.com/viewrep/jptools/jpTools/lib




import java.io.File;
import java.io.*;
import jxl.*;
import java.util.*;
import jxl.Workbook;
import jxl.read.biff.*;


class ReadXls
{
public static void main(String[] args)
{
try
{
String filename = "C:/ExcelFileName.xls";
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));

Workbook workbook = Workbook.getWorkbook( new File(filename),ws);

Sheet s = workbook.getSheet(0);
System.out.println("Sheet Content::"+s.getName());
readDataSheet(s);
workbook.close();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (BiffException e)
{
e.printStackTrace();
}
private static void readDataSheet(Sheet s)
{
// Find the labeled cell from sheet
System.out.println(lc.getString());

//gets the value of cell at specified column and row
DateCell dc = (DateCell) s.getCell(20,1);
System.out.println(dc);

}
}

3 comments:

Vasuu said...

hi..
its quite informative.. thank u but can u pls let me know if this jxl jar file also supports ods(sun open office file).

sac@nitw said...

hey thnx for all this information but still i would like to know tht u have used
"lc" as labelled cell object ..but how to define and declare this ... i cant understand

Unknown said...

thanks but
can u give java swing programs
examples with explanation