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.
Code Java:
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());
}
}
}
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.
Re: Appending to excel using POI
Here I m giving my code. I am using Eclipse.On run it is giving thaterror ""Error:org.apache.poi.hssf.usermodel.HSSFShee t" in console block. Please help me in this regard.
Thanks in advance.
Code Java:
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());
}
}
}
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.
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.
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.
Re: Appending to excel using POI
is:
import org.apache.poi.hssf.usermodel.HSSFSheet;
supposed to be:
import org.apache.poi.hslf.usermodel.HSSFSheet;
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.
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.