I must reach variable inside the while loop. I know if i declare variable outside of loop i can reach it. But variable must inside the loop in this scenario. Let me explain with an example;
while (rs.next()) {
HSSFRow row2 = sheet.createRow((short) index);
Cell cell5 = row2.createCell((short) 0);
cell5.setCellValue(rs.getString(1));
cell5.setCellStyle(stylezones);
Cell cell6 = row2.createCell((short) 1);
cell6.setCellValue(rs.getInt(2));
cell6.setCellStyle(styledatathousand);
Cell cell7 = row2.createCell((short) 2);
cell7.setCellValue(rs.getInt(3));
cell7.setCellStyle(styledatathousand);
Cell cell8 = row2.createCell((short) 3);
cell8.setCellValue(rs.getDouble(4));
cell8.setCellStyle(styledatadouble);
index++;
rscount++;
}
This scenario create excel row for every resultset row as you can see. Loop increase row index every time and create new row for new resultset row. Only 3 columns using but list is long as vertical. If i want add data to 4th cell of same row i cant. Because rows already created by loop. If i can reach "row2" variable from outside i can add cell to 4th column just like this;
Cell cell9 = row2.createCell((short) 4);
cell9.setCellValue("example string");
cell9.setCellStyle(styledatadouble);
Any way create row start from cell index 4 in poi? Or anyway reach while loop variable from outside?
在while循环之后,可以使用sheet.getRow(2)
再次检索行。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.