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 9 of 9

Thread: Appending to excel using POI

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Appending to excel using POI

    Dear All,

    I want to append data to a existing excel sheet. For this am using POI API and I have given the full path
    of Jar file of this API into class path in envornment varaibles .

    It is giving the following error
    org.apache.poi.hssf.usermodel.HSSFSheet when I tried to run the code.

    Please help in this..

    Thanks in advance



    Here I m giving my code. I am using Eclipse.On run it is giving thaterror ""Errorrg.apache.poi.hssf.usermodel.HSSFShee t" in console block. Please help me in this regard.
    Thanks in advance.

    import java.io.*;
    import java.util.*;
    import org.apache.poi.ss.usermodel.WorkbookFactory;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hslf.model.*;
    import org.apache.poi.hslf.exceptions.*;
     
    public class Testing {
     
    public Testing() {
    }
     
    public static void main(String[] args) throws IOException, InvalidRecordFormatException{
    // TODO Auto-generated method stub
     
    try{
    FileInputStream fstream = new FileInputStream("test.xls");
    org.apache.poi.ss.usermodel.Workbook wb = (org.apache.poi.ss.usermodel.Workbook)WorkbookFact ory.create(fstream); 
    Sheet sheet =(Sheet)wb.getSheetAt(1); 
    Row row = (Row)((org.apache.poi.ss.usermodel.Sheet)sheet).ge tRow(375); 
    Cell cell=row.createCell(0);
    cell.setCellValue(10);
    FileOutputStream fileout=new FileOutputStream("test.xls");
    wb.write(fileout);
    fileout.close();
    }
    catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
     
     
    }
     
    }
    }
    Last edited by helloworld922; August 18th, 2010 at 12:12 PM. Reason: It will help them to suggest me.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Appending to excel using POI

    That cannot be the entire error. It doesnt even tell you what the error is for...

    Try to pinpoint exactly where that error occurs in your code. It will be easier to work from there.

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Appending to excel using POI

    Here I m giving my code. I am using Eclipse.On run it is giving thaterror ""Errorrg.apache.poi.hssf.usermodel.HSSFSheet" in console block. Please help me in this regard.
    Thanks in advance.

    import java.io.*;
    import java.util.*;
    import org.apache.poi.ss.usermodel.WorkbookFactory;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hslf.model.*;
    import org.apache.poi.hslf.exceptions.*;
     
    public class Testing {
     
    	public Testing() {
    			}
     
    	public static void main(String[] args) throws IOException, InvalidRecordFormatException{
    		// TODO Auto-generated method stub
     
    			  try{
    		FileInputStream fstream = new FileInputStream("test.xls");
      org.apache.poi.ss.usermodel.Workbook wb = (org.apache.poi.ss.usermodel.Workbook)WorkbookFactory.create(fstream); 
    	    Sheet sheet =(Sheet)wb.getSheetAt(1); 
    	    Row row = (Row)((org.apache.poi.ss.usermodel.Sheet)sheet).getRow(375); 
            Cell cell=row.createCell(0);
            cell.setCellValue(10);
            FileOutputStream fileout=new FileOutputStream("test.xls");
    	      wb.write(fileout);
    	      fileout.close();
    	  }
    	  catch (Exception e){//Catch exception if any
    	      System.err.println("Error: " + e.getMessage());
     
     
    	}
     
    }
    }
    Last edited by helloworld922; August 18th, 2010 at 12:13 PM.

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Appending to excel using POI

    I dont used Eclipse and I have never used POI, but heres a thought.

    You make the call: Sheet sheet =(Sheet)wb.getSheetAt(1); .

    Does the Excel WorkBook have 2 sheets? Because I would guess that the getSheetAt method gets an index number (starting with 0) for those sheets. Which means Sheet sheet =(Sheet)wb.getSheetAt(1); would be trying to get sheet number 2.

  5. #5
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Appending to excel using POI

    Yes It has four sheets.and it has more than 375 rows.Please help me on this.
    Thanks in advance.

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Appending to excel using POI

    please surround your code with highlight tags. If you are unsure how to do this, you can read my signature.

  7. #7
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Appending to excel using POI

    is:
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    supposed to be:
    import org.apache.poi.hslf.usermodel.HSSFSheet;

  8. #8
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Appending to excel using POI

    @helloworld922..

    I am not getting....how to do surround code with highlight tags.....Is it just the delighter?
    Please can u tell me when this error:"Error: org.apache.poi.hssf.usermodel.HSSFSheet" encounter.
    Means where i am lacking.Please help me in this regard.
    Thanks in advance.

  9. #9
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Appending to excel using POI

    @aussiemcgr...

    I tried import org.apache.poi.hslf.usermodel.HSSFSheet; instead of import org.apache.poi.hssf.usermodel.HSSFSheet;
    But I think its not a package.Its giving error.

Similar Threads

  1. Importing excel data
    By supriya ramjee in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: October 20th, 2012, 09:39 AM
  2. appending from shell script to excel sheet
    By krishnamohan in forum Java Theory & Questions
    Replies: 1
    Last Post: August 16th, 2010, 10:01 AM
  3. conversions and excel
    By mkslt4 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 10th, 2010, 01:54 AM
  4. Help needed in excel download...
    By tester in forum Java Servlet
    Replies: 2
    Last Post: February 9th, 2010, 08:14 AM
  5. Export to excel
    By ebosysindia in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: May 14th, 2009, 06:25 AM