see the code below, put it after printing function, U just need to add some libraries to ur Package to get it work
try {
System.out.println("Suseccfully >> Go to D drive to see the result ");
FileOutputStream fileOut = new FileOutputStream("D://ResultS.xls");
@SuppressWarnings("resource")
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet worksheet = workbook.createSheet("Enizi");
HSSFCellStyle headcellStyle = workbook.createCellStyle();
HSSFCellStyle content_cellStyle = workbook.createCellStyle();
headcellStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
headcellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
headcellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
headcellStyle.setBorderRight(HSSFCellStyle.BORDER_THICK);
content_cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFRow row1 = worksheet.createRow((short) 0);
HSSFCell cellS1 = row1.createCell((short) 0);
cellS1.setCellValue("Cloudlet ID");
cellS1.setCellStyle(headcellStyle);
HSSFCell cellB1 = row1.createCell((short) 1);
cellB1.setCellValue("STATUS");
cellB1.setCellStyle(headcellStyle);
HSSFCell cellD1 = row1.createCell((short) 2);
cellD1.setCellValue("Data center ID");
cellD1.setCellStyle(headcellStyle);
HSSFCell cellH1 = row1.createCell((short) 3);
cellH1.setCellValue("VM ID");
cellH1.setCellStyle(headcellStyle);
HSSFCell cellv1 = row1.createCell((short) 7);
cellv1.setCellValue("LENGTH");
cellv1.setCellStyle(headcellStyle);
HSSFCell cellE1 = row1.createCell((short) 4);
cellE1.setCellValue("TIME");
cellE1.setCellStyle(headcellStyle);
HSSFCell cellF1 = row1.createCell((short) 5);
cellF1.setCellValue("START_TIME");
cellF1.setCellStyle(headcellStyle);
HSSFCell cellG1 = row1.createCell((short) 6);
cellG1.setCellValue("FINISH_TIME");
cellG1.setCellStyle(headcellStyle);
// DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) { // loop for printing
cloudlet = list.get(i);
HSSFRow row2 = worksheet.createRow( cloudlet.getCloudletId() + 1); // Row no. cloudlet.getCloudletId() // replacement for i
HSSFCell cellA = row2.createCell((short) 0); // Column no.
cellA.setCellValue(cloudlet.getCloudletId());
cellA.setCellStyle(content_cellStyle);
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
HSSFCell cellA1 = row2.createCell((short) 1); // colume no.
cellA1.setCellValue("SUCCESS");
cellA1.setCellStyle(content_cellStyle);
HSSFCell cellA2 = row2.createCell((short) 2); // colume no.
cellA2.setCellValue(cloudlet.getResourceId());
cellA2.setCellStyle(content_cellStyle);
HSSFCell cellA3 = row2.createCell((short) 3); // colume no.
cellA3.setCellValue(cloudlet.getVmId());
cellA3.setCellStyle(content_cellStyle);
HSSFCell cellA7 = row2.createCell((short) 7); // colume no.
cellA7.setCellValue(cloudlet.getCloudletLength());
cellA7.setCellStyle(content_cellStyle);
HSSFCell cellA4 = row2.createCell((short) 4); // colume no.
//cellA4.setCellValue(dft.format(cloudlet.getActualCPUTime()));
cellA4.setCellValue(cloudlet.getActualCPUTime());
cellA4.setCellStyle(content_cellStyle);
HSSFCell cellA5 = row2.createCell((short) 5); // colume no.
//cellA5.setCellValue(dft.format(cloudlet.getExecStartTime()));
cellA5.setCellValue(cloudlet.getExecStartTime());
cellA5.setCellStyle(content_cellStyle);
HSSFCell cellA6 = row2.createCell((short) 6); // colume no.
//cellA6.setCellValue(dft.format(cloudlet.getFinishTime()));
cellA6.setCellValue(cloudlet.getFinishTime());
cellA6.setCellStyle(content_cellStyle);
}
}
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}