JavaMix

it`s all about JavaPrograming

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

JavaMix Blog

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);

}

}

JavaMix Blog


Written by katta vijay

March 26, 2009 at 12:15 pm

21 Responses

Subscribe to comments with RSS.

  1. […] a comment » before going to use this post My strong advice to see this post […]

  2. article is much Handy and clear, thank you

    rakesh

    May 21, 2009 at 5:50 pm

  3. Hi Vijay,
    I need your help how to convert text into wav file using FreeTTS

    http://forums.sun.com/thread.jspa?threadID=5371491&tstart=0

    Thanks
    Regards
    Rajesh

    Rajesh

    June 1, 2009 at 3:53 pm

  4. @rajesh

    how can i help u? where did u strucked up ?

    katta vijay

    June 1, 2009 at 4:07 pm

    • im not able to create .wav file yaar.The below is my code.in the forum you menioned that you solved the probelm of creating the wav file

      import com.sun.speech.freetts.FreeTTS;
      import com.sun.speech.freetts.Voice;
      import com.sun.speech.freetts.VoiceManager;

      public class VoiceTest {

      /**
      * @param args the command line arguments
      */

      public void audioGenerated(String s)
      {
      Voice voice;

      voice=VoiceManager.getInstance().getVoice(“kevin16”);
      if(voice!=null)
      {
      voice.allocate();
      }
      FreeTTS freetts=new FreeTTS(voice);
      for(int i=0;i<s.length();i++)
      {
      String talk=String.valueOf(s.charAt(i));
      voice.speak(talk);
      }
      freetts.startup();
      freetts.shutdown();
      }
      public static void main(String args[])
      {
      VoiceTest voice =new VoiceTest();
      String s="rajesh";
      voice.audioGenerated(s);
      }

      }

      Thanks
      Regards
      Rajesh

      Rajesh

      June 1, 2009 at 4:58 pm

      • i tried theses two lines

        freetts.setStreamingAudio(true);
        freetts.setAudioFile(“c:\\test.wav”);

        like

        freetts.startup();
        freetts.setStreamingAudio(true);
        freetts.setAudioFile(“c:\\test.wav”);
        freetts.shutdown();

        Thanks

        Rajesh

        June 1, 2009 at 4:59 pm

      • ok,
        what kind of application ur developing ?
        if ur developing a web application the code at (reply 3 of 10) http://forums.sun.com/thread.jspa?messageID=10653752#10653752
        is working perfectly.
        do u need explanation for that code ??
        ask me.

        katta vijay

        June 1, 2009 at 5:33 pm

      • My Application is the webapplication, my requirement is to develop voice based captcha.for that im usisng FreeTTS.What the problem in my code yaar.why the output file is not created

        Rajesh

        June 1, 2009 at 5:50 pm

      • Hi Vijay,
        The code in the reply3 of 10 in the forum is not working.i.e he output wav file is not created.if possible can u send me any code that works fine with creating output wav file

        Rajesh

        June 1, 2009 at 5:57 pm

      • Hi Vijay,
        The code in the reply3 of 10 in the forum is not working.i.e he output wav file is not created.if possible can u send me any code that works fine with creating output wav file.can u send me ur gmail id .mine is GTALK: rajeshsofware@gmail.com

        Rajesh

        June 1, 2009 at 5:57 pm

    • throwing error main not found
      but i have checked very thing

      chris

      August 20, 2010 at 4:38 pm

  5. Hi Vijay,
    Sorry for disturbing u again.My code is working fine now.but one thing im getting in my console always “System property “mbrola.base” is undefined. Will not use MBROLA voices”. how to avoid this message. client ask me to look into this issue as an error message.

    please help me if u find time

    Thanks
    Rajesh

    rajesh

    June 11, 2009 at 5:31 pm

  6. how to read data from excel file using column name.
    Say for eg,
    Place Country
    Chennai India
    Mumbai India
    Need to read using the column Place, Country.
    Please help me out.

    Uma

    September 11, 2009 at 9:46 am

  7. Excuse me for writing OFFTOPIC … which WP theme do you use? It’s looking interesting.

    Jaccuccawbamy

    December 12, 2009 at 10:36 am

  8. @Jaccuccawbamy
    The Journalist v1.9 by Lucian E. Marin,

    you can find it here http://lucianmarin.com/page/themes/

    katta vijay

    December 12, 2009 at 6:41 pm

  9. […] going to use this post My strong advice to see this post […]

  10. Hi…. Thanks for this useful post.. But Can you explain how to fetch all the rows from the excel sheet? here its just for three rows. The files that i use have a variable row count. So i need to be able to write a code that adapts to the length of the row

    Jagadis

    January 30, 2010 at 2:59 pm

  11. Thanks. Its a very useful post

    Premalatha

    March 29, 2010 at 6:04 pm

  12. hi there u doin a good job… i need ur help in adding this feedjit can u help me to add this widget in the wordpress blog. coz tere is no any option for the WordPress.com therz only WordPress.org… so thx in advance..! my email id is hitesh.parmar915@gmail.com and my WordPress id is http://parmarhh.wordpress.com/
    Thx Bye Bye.

    parmarhh

    August 3, 2010 at 10:19 pm

  13. OMG! Finally I found something simple and so clear! Thanks. But.. I cant read one of my excel files I got error:

    Text Object on sheet “Mesafeler Cetveli” not supported – omitting

    Any chance you know something about it?!

    Jonas

    January 3, 2012 at 10:12 pm


Comments are closed.