我创建了可以通过数据库访问数据的代码,然后将数据写入 Excel 工作表中。
现在数据已成功写入。但问题是当数据被写入excel文件第一列的excel表时,所有数据都正确写入。
但是在第二列时,行打印在第二列中,最后一行从第一列结束。
我想并排打印列。请参阅此图片链接以获得更好的理解。请说明一下,这将有助于回答我的问题。为了简单起见,我缩短了我的代码。
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);
}