| | |

Reading data from Excel sheet using JExcel API

using Java we can read the data from Excel sheets by creating type1 driver , but here we are taking help of JExcelapi we can able to read data directly from the Excel sheets.

steps to be follow:

step 1:

download JExcel api from here

step2:

after downloading extract the zip file. make jxl.jar available to your class path.

step 3:

create a Excel sheet with some data .

step 4:

in this step we are reading data from the Excel sheet.

use the below java code:

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

// this is main java program

//describes how to read from the .xls and displays

package excelsheetreading; // my package name

import java.io.File;

import java.io.IOException;

import java.util.Date;

import jxl.*;

import jxl.read.biff.BiffException;

/**

*

* @author vijay

*/

public class Main // main is my class name

{

/**

* @param args the command line arguments

*/

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

// TODO code application logic here

Workbook workbook = Workbook.getWorkbook(new File(“C:/Documents and Settings/vijay/Desktop/contacts.xls”));

// my excel sheet name is contacts, iam given the complete path.

Sheet sheet = workbook.getSheet(0); // iam reading data from the sheet1

// here iam reading the data of 1st column data up three cells

Cell a1 = sheet.getCell(0,0);

Cell b2 = sheet.getCell(0,1);

Cell c2 = sheet.getCell(0,2);

//getting  the data from cells

String stringa1 = a1.getContents();

String stringb2 = b2.getContents();

String stringc2 = c2.getContents();

//printing the data

System.out.println(“a1–>”+stringa1);

System.out.println(“b2–>”+stringb2);

System.out.println(“c3–>”+stringc2);

}

}

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *