Reading xls using JXL (Java Excel Library)!!

10:03 PM 0 Comments

Program to Read the xls using the JExcel as Follows:

1. Download the JXL jar from the following location. Add the jar to the Build Path of the project.
 http://mirrors.ibiblio.org/pub/mirrors/maven/net.sourceforge.jexcelapi/jars/jxl-2.6.jar

2. Link for JXL API.  http://jexcelapi.sourceforge.net/

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;


public class ReadExcel {

public static void main(String[] args) throws BiffException, IOException {

File f = new File("inputData.xls");
Workbook w = Workbook.getWorkbook(f);
Sheet sheet = w.getSheet(0);
int rows = sheet.getRows();
int cols=sheet.getColumns();
String inputData[][] =new String[rows][cols];
for(int i =0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
Cell cell =sheet.getCell(j,i);//Column , row
String str =cell.getContents();
System.out.print(str);
inputData[i][j]= str;
}
System.out.println();
}
}

}

.xls File


Unknown

This site creates a platform to become an expert by gaining knowledge of unknown real-time issues as well.

0 comments: