Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to Read data from Datasheet of an Excel sheet using Java?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How to Read data from Datasheet of an Excel sheet using Java?

    Hello,
    I wrote a code to read the data in an Excel sheet.Its working fine and i want to read the data of other sheet in same excel sheet.and i have to use that on in other function.How to do this?Can any one explain about this.
    public static Vector ReadExcel(String fileName) {
            Vector vectorData = new Vector();
            //ReadExcel R = new ReadExcel();
     
            try {
                FileInputStream fileInputStream = new FileInputStream(fileName);
     
                XSSFWorkbook ObjWorkBook = new XSSFWorkbook(fileInputStream);
     
                [B]// Read data at sheet 0[/B] [B]I want to read the data for sheet 1..and i have to use that one in other function Like displayDataExcelXLSX[/B]//
                XSSFSheet ObjSheet = ObjWorkBook.getSheetAt(0);           
                Iterator rowIteration = ObjSheet.rowIterator();
                // Looping every row at sheet 0
                while (rowIteration.hasNext()) {
                    XSSFRow Row = (XSSFRow) rowIteration.next();
                    Iterator cellIteration = Row.cellIterator();               
                    Vector CellEachRowData = new Vector();
     
                    // Looping every cell in each row at sheet 0
                    while (cellIteration.hasNext()) {
                        XSSFCell Cell = (XSSFCell) cellIteration.next();
                        CellEachRowData.addElement(Cell);
                    }
     
                    vectorData.addElement(CellEachRowData);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
     
            return vectorData;
        }
    I would like to use sheet1 data in this function.
    public static void displayDataExcelXLSX(Vector vectorData) {
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to Read data from Datasheet of an Excel sheet using Java?

    i want to read the data of other sheet in same excel sheet
    I don't understand the question. A sheet within a sheet? Are you saying you want to read a sheet other than the one at index 0? If so, then get the sheet at the index you wish and read it as you method posted does. You may be better off creating a method which reads the sheet at a particular index and returns the data as a List - thus you can reuse this method for whatever sheet index you want.

Similar Threads

  1. How does Java handle the data in Excel sheet?
    By datathinker in forum JDBC & Databases
    Replies: 1
    Last Post: August 1st, 2013, 07:27 AM
  2. Replies: 7
    Last Post: May 28th, 2013, 09:03 AM
  3. exprot data from excel sheet to DataBase
    By chiranjeevireddy in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 20th, 2013, 07:58 AM
  4. read excel sheet into database
    By shri in forum JDBC & Databases
    Replies: 7
    Last Post: March 8th, 2013, 12:51 AM
  5. how to read chinese data from excel to java
    By swapna in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 17th, 2011, 07:02 AM

Tags for this Thread