I am having a problem here while writing some data to an Excel sheet by using Apache POI. I want to call a function several times which will write the data into Excel sheet that I have created.
Is there any way that I can move the pointer to the next row every time at the end of the function???
My code is given below...
public static void excelLog(String filename , String message)
{
String dest="D:\\testexcel.xls";
HSSFWorkbook myWorkBook = new HSSFWorkbook();
HSSFSheet mySheet = myWorkBook.createSheet();
HSSFRow myRow = null;
HSSFCell myCell = null;
String excelData [][] = new String [1][2];
excelData[0][0]=filename;
excelData[0][1]=message;
myRow = mySheet.createRow(rowNum);
for (int cellNum = 0; cellNum < 2 ; cellNum++){
myCell = myRow.createCell((short) cellNum);
myCell.setCellValue(excelData[rowNum][cellNum]);
}
rowNum++;
try{
FileOutputStream out = new FileOutputStream(dest);
myWorkBook.write(out);
out.close();
}catch(Exception e){
e.printStackTrace();
}
}
Please help me in this. Thank you :)