I want to write to data which contains ArrayList of String to excel using java. When i am doing only the first data only writing to excel.remaining data is not.
public class ExcelGenerator {
public static void main(String args[]) throws FileNotFoundException, HPSFException, IOException, SQLException, NestableException
{
ArrayList<String> arrlist = new ArrayList<String>();
arrlist.add("14");
arrlist.add("7");
arrlist.add("39");
arrlist.add("40");
/* For Loop for iterating ArrayList */
System.out.println("For Loop");
for (int counter = 0; counter < arrlist.size(); counter++) {
System.out.println(arrlist.get(counter));
}
HSSFWorkbook workbook=new HSSFWorkbook();
File f=new File("D:/Test/test.xls");
GeericExcelGenerator gl=new GeericExcelGenerator("Test",workbook);
FileOutputStream outputStream=new FileOutputStream(f);
gl.generate(outputStream,arrlist);
}
public void generate(OutputStream outputStream,ArrayList arrlist) throws SQLException, IOException, NestableException
{
try
{
int currentRow = 0;
for (int counter = 0; counter < arrlist.size(); counter++) {
HSSFRow row = sheet.createRow(currentRow);
System.out.println("Description is"+arrlist.get(counter));
String c=(String) arrlist.get(counter);
int i=0;
HSSFCell cell = HSSFCellUtil.createCell(row, i, null);
cell.setCellValue(c);
i++;
workbook.write(outputStream);
currentRow++;
currentRow++;
}
}catch(IOException e)
{}
finally {
outputStream.close();
}
}
}
sheetvariable suddely come from? I don't see it initialized anywhere. This cant' compile.