Results 1 to 8 of 8
  1. #1
    nagaraj is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Question How to read Excel file in java

    Hi All

    I'm new to java, and i want to know how to read excel file. i have did using poi API but i getting the following error please help me out in this issue.

    C:\sai\Excel>java ReadExcel
    Exception in thread "main" java.lang.NoClassDefFoundError: ReadExcel
    Caused by: java.lang.ClassNotFoundException: ReadExcel
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: ReadExcel. Program will exit.

    I am able to compile the program but i am not able to run it.

    Thanks in Advance

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    I think you have mistake in path of file, which you want to read. Can you show your code?
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    nagaraj is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Smile Here is the my code

    Thanks for the response,

    Please find my code here
    Java Code:
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import java.io.FileInputStream;
    
    /**
    * This is a sample to Read an Excel Sheet using Jakarta POI API
    *
    * @author Nitin Aggarwal
    * @version 1.0
    */
    public class ReadExcel {
    /** Location where the Excel has to be read from. Note the forward Slash */
    public static String fileToBeRead = "c:/sai/Test.xls";
    
    public static void main(String argv[]) {
    try {
    // Create a work book reference
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
    fileToBeRead));
    // Refer to the sheet. Put the Name of the sheet to be referred from
    // Alternative you can also refer the sheet by index using
    // getSheetAt(int index)
    // HSSFSheet sheet = workbook.getSheet(“sheet1?);
    HSSFSheet sheet = workbook.getSheetAt(0);
    // Reading the TOP LEFT CELL
    HSSFRow row = sheet.getRow(0);
    // Create a cell ate index zero ( Top Left)
    HSSFCell cell = row.getCell((short) 0);
    // Type the content
    //System.out.println("THE TOP LEFT CELL–> "+ cell.getRichStringCellValue());
    System.out.println("Hello");
    
    } catch (Exception e) {
    System.out.println("!! Bang !! xlRead() : " + e);
    }
    
    }
    
    }
    :)
    Last edited by Eranga; 03-17-2011 at 11:26 AM.

  4. #4
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    This problem is not related to Excel, there is some generic problem

    First compile your program properly and then check for Class file generated or not and then from same location run the program
    sanjeev,संजीव

  5. #5
    nagaraj is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Hi sanjeev,

    I'm able to compile the program without any errors and class file is also generated. the problem is when i'm running the program i'm getting the error as shown in the above post.

    Thanks.

  6. #6
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Ok

    do one thing make a simple Hello World java program and try to run that program in the same directory where you are running your ReadExcel program and then let us know the results
    sanjeev,संजीव

  7. #7
    nagaraj is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    sanjeev

    I'm able run Hello World java program successfully from the same directory


    Thanks

  8. #8
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Can you please provide a jar for the API

    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    sanjeev,संजीव

Similar Threads

  1. JXL read excel documents
    By ironicending in forum Java Applets
    Replies: 1
    Last Post: 09-08-2010, 12:42 AM
  2. how to read excel file through java program
    By madhuragowda in forum New To Java
    Replies: 2
    Last Post: 04-16-2010, 08:53 AM
  3. Read pasword protected Excel file
    By vijay7539 in forum Advanced Java
    Replies: 1
    Last Post: 11-27-2009, 05:13 PM
  4. How to Read Excel file??
    By spalax in forum New To Java
    Replies: 3
    Last Post: 08-15-2009, 05:06 AM
  5. How to read Excel file with java
    By chetan-24 in forum New To Java
    Replies: 5
    Last Post: 04-22-2009, 05:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •