I have created code in which data is accessible through the database and then that data is written in the excel sheet.
Now data is written successfully. But the issue is when the data is get written in the excel sheet at the first column of the excel file writes all data properly.
But at the time of the second column, the rows are printed in the second column from where the last row is ended from the first column.
I want to print column side by side. please refer to this image link for more better understanding. Please, shed some light it will be helpful to answer my question. I have shortened up my code for simplicity.
Integer col = 5;
Double sl_counter = 0.0;
Double coff_counter = 0.0;
try {
ConnectionClass cn = new ConnectionClass();
Connection con = cn.connectDb();
String filename = "E:\\export.csv" ;
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("FirstSheet");
HSSFRow leave_count = sheet.createRow((short)4);
while(rs7.next()){
HSSFRow SL = sheet.createRow(col);
SL.createCell(17).setCellValue(rs7.getString("leave_Date"));
col++;
sl_counter++;
}
while(rs11.next()){
HSSFRow SL = sheet.createRow(col);
SL.createCell(17).setCellValue(rs11.getString("leave_Date")+" (FIRST HALF DAY)");
col++;
sl_counter += 0.5;
}
while(rs15.next()){
HSSFRow SL= sheet.createRow(col);
SL.createCell(17).setCellValue(rs15.getString("leave_Date")+" (SECOND HALF DAY)");
col++;
sl_counter += 0.5;
}
leave_count.createCell(17).setCellValue(sl_counter);
//int cols = 5;
while(rs8.next()){
HSSFRow leave_date = sheet.createRow(col);
leave_date.createCell(18).setCellValue(rs8.getString("leave_Date"));
col++;
coff_counter++;
}
while(rs12.next()){
HSSFRow leave_date = sheet.createRow(col);
leave_date.createCell(18).setCellValue(rs12.getString("leave_Date")+" (FIRST HALF DAY)");
col++;
coff_counter += 0.5;
}
while(rs16.next()){
HSSFRow leave_date = sheet.createRow(col);
leave_date.createCell(18).setCellValue(rs16.getString("leave_Date")+" (SECOND HALF DAY)");
col++;
coff_counter += 0.5;
}
leave_count.createCell(18).setCellValue(coff_counter);
FileOutputStream fileOut = new FileOutputStream(filename);
workbook.write(fileOut);
fileOut.close();
// workbook.close();
cl_counter = 0.0;
col = 0;
} catch ( Exception ex ) {
System.out.println(ex);
}