gpt4 book ai didi

java - Apache POI 未在 Excel 中为每一列呈现输出

转载 作者:行者123 更新时间:2023-11-30 03:06:55 24 4
gpt4 key购买 nike

我正在使用 apache POI 从数据库读取数据并渲染到 Excel。我用的是Oracle数据库。我在 Excel 中的预期输出是 desired output

excel中的实际输出是actual output

其中员工的名字是 Devendra Singh 和 Yuvraj Verma。下面是它们各自的 token 编号:A1359 和 A1539。 R、W、FH、OTR、OTW、OTFH 是每个员工的生产值。

使用 System.out.print 时,代码显示正确的位置,但不在 Excel 工作表中。也不异常(exception)。

        //method to create cells
private static void createCell(XSSFWorkbook wb, XSSFRow row, short column, short halign, short valign,Object value) {
System.out.println("Creating row #"+row.getRowNum() + " Colm# "+column+" value "+value);
XSSFCell cell = row.createCell(column);
cell.setCellValue(value.toString());
CellStyle cellStyle = wb.createCellStyle();
if(column == 1) {
XSSFDataFormat df = wb.createDataFormat();
cellStyle.setDataFormat(df.getFormat("d mmm yy"));
}
cellStyle.setAlignment(halign);
cellStyle.setVerticalAlignment(valign);

cell.setCellStyle(cellStyle);
}

在 System.out.println() 中获取输出为

            name DEVENDRA SINGH token:A1359 category:D depart:14 month:11 year:2015
Creating row #1 Colm# 2 value DEVENDRA SINGH
Creating row #2 Colm# 2 value A1359
Creating row #3 Colm# 2 value R
Creating row #3 Colm# 3 value W
Creating row #3 Colm# 4 value FH
Creating row #3 Colm# 5 value OT-R
Creating row #3 Colm# 6 value OT-W
Creating row #3 Colm# 7 value OT-FH
Creating row #4 Colm# 1 value 01/Nov/2015
Creating row #4 Colm# 2 value 12
Creating row #4 Colm# 3 value 3
Creating row #4 Colm# 4 value 4
Creating row #4 Colm# 5 value 5
Creating row #4 Colm# 6 value 6
Creating row #4 Colm# 7 value 7
Creating row #5 Colm# 1 value 02/Nov/2015
Creating row #5 Colm# 2 value 5
Creating row #5 Colm# 3 value 2
Creating row #5 Colm# 4 value 5
Creating row #5 Colm# 5 value 3
Creating row #5 Colm# 6 value 3
Creating row #5 Colm# 7 value 4
Creating row #6 Colm# 1 value 03/Nov/2015
Creating row #6 Colm# 2 value 0
Creating row #6 Colm# 3 value 0
Creating row #6 Colm# 4 value 0
Creating row #6 Colm# 5 value 0
Creating row #6 Colm# 6 value 0
Creating row #6 Colm# 7 value 0
Creating row #7 Colm# 1 value 04/Nov/2015
Creating row #7 Colm# 2 value 0
Creating row #7 Colm# 3 value 9
Creating row #7 Colm# 4 value 0
Creating row #7 Colm# 5 value 0
Creating row #7 Colm# 6 value 6
Creating row #7 Colm# 7 value 0
Creating row #8 Colm# 1 value 05/Nov/2015
Creating row #8 Colm# 2 value 3
Creating row #8 Colm# 3 value 0
Creating row #8 Colm# 4 value 0
Creating row #8 Colm# 5 value 0
Creating row #8 Colm# 6 value 6
Creating row #8 Colm# 7 value 0
Creating row #9 Colm# 1 value 06/Nov/2015
Creating row #9 Colm# 2 value 0
Creating row #9 Colm# 3 value 0
Creating row #9 Colm# 4 value 0
Creating row #9 Colm# 5 value 0
Creating row #9 Colm# 6 value 0
Creating row #9 Colm# 7 value 0
Creating row #10 Colm# 1 value 07/Nov/2015
Creating row #10 Colm# 2 value 0
Creating row #10 Colm# 3 value 0
Creating row #10 Colm# 4 value 0
Creating row #10 Colm# 5 value 0
Creating row #10 Colm# 6 value 0
Creating row #10 Colm# 7 value 0
Creating row #11 Colm# 1 value 08/Nov/2015
Creating row #11 Colm# 2 value 0
Creating row #11 Colm# 3 value 0
Creating row #11 Colm# 4 value 0
Creating row #11 Colm# 5 value 0
Creating row #11 Colm# 6 value 0
Creating row #11 Colm# 7 value 0
Creating row #12 Colm# 1 value 09/Nov/2015
Creating row #12 Colm# 2 value 0
Creating row #12 Colm# 3 value 0
Creating row #12 Colm# 4 value 0
Creating row #12 Colm# 5 value 0
Creating row #12 Colm# 6 value 0
Creating row #12 Colm# 7 value 0
Creating row #13 Colm# 1 value 10/Nov/2015
Creating row #13 Colm# 2 value 0
Creating row #13 Colm# 3 value 0
Creating row #13 Colm# 4 value 0
Creating row #13 Colm# 5 value 0
Creating row #13 Colm# 6 value 0
Creating row #13 Colm# 7 value 0
Creating row #14 Colm# 1 value 11/Nov/2015
Creating row #14 Colm# 2 value 0
Creating row #14 Colm# 3 value 0
Creating row #14 Colm# 4 value 0
Creating row #14 Colm# 5 value 0
Creating row #14 Colm# 6 value 0
Creating row #14 Colm# 7 value 0
Creating row #15 Colm# 1 value 12/Nov/2015
Creating row #15 Colm# 2 value 0
Creating row #15 Colm# 3 value 0
Creating row #15 Colm# 4 value 0
Creating row #15 Colm# 5 value 0
Creating row #15 Colm# 6 value 0
Creating row #15 Colm# 7 value 0
Creating row #16 Colm# 1 value 13/Nov/2015
Creating row #16 Colm# 2 value 0
Creating row #16 Colm# 3 value 0
Creating row #16 Colm# 4 value 0
Creating row #16 Colm# 5 value 0
Creating row #16 Colm# 6 value 0
Creating row #16 Colm# 7 value 0
Creating row #17 Colm# 1 value 14/Nov/2015
Creating row #17 Colm# 2 value 0
Creating row #17 Colm# 3 value 0
Creating row #17 Colm# 4 value 0
Creating row #17 Colm# 5 value 0
Creating row #17 Colm# 6 value 0
Creating row #17 Colm# 7 value 0
Creating row #18 Colm# 1 value 15/Nov/2015
Creating row #18 Colm# 2 value 0
Creating row #18 Colm# 3 value 0
Creating row #18 Colm# 4 value 0
Creating row #18 Colm# 5 value 0
Creating row #18 Colm# 6 value 0
Creating row #18 Colm# 7 value 0
Creating row #19 Colm# 1 value 16/Nov/2015
Creating row #19 Colm# 2 value 0
Creating row #19 Colm# 3 value 0
Creating row #19 Colm# 4 value 0
Creating row #19 Colm# 5 value 0
Creating row #19 Colm# 6 value 0
Creating row #19 Colm# 7 value 0
Creating row #20 Colm# 1 value 17/Nov/2015
Creating row #20 Colm# 2 value 0
Creating row #20 Colm# 3 value 0
Creating row #20 Colm# 4 value 0
Creating row #20 Colm# 5 value 0
Creating row #20 Colm# 6 value 0
Creating row #20 Colm# 7 value 0
Creating row #21 Colm# 1 value 18/Nov/2015
Creating row #21 Colm# 2 value 0
Creating row #21 Colm# 3 value 0
Creating row #21 Colm# 4 value 0
Creating row #21 Colm# 5 value 0
Creating row #21 Colm# 6 value 0
Creating row #21 Colm# 7 value 0
Creating row #22 Colm# 1 value 19/Nov/2015
Creating row #22 Colm# 2 value 0
Creating row #22 Colm# 3 value 0
Creating row #22 Colm# 4 value 0
Creating row #22 Colm# 5 value 0
Creating row #22 Colm# 6 value 0
Creating row #22 Colm# 7 value 0
Creating row #23 Colm# 1 value 20/Nov/2015
Creating row #23 Colm# 2 value 0
Creating row #23 Colm# 3 value 0
Creating row #23 Colm# 4 value 0
Creating row #23 Colm# 5 value 0
Creating row #23 Colm# 6 value 0
Creating row #23 Colm# 7 value 0
Creating row #24 Colm# 1 value 21/Nov/2015
Creating row #24 Colm# 2 value 0
Creating row #24 Colm# 3 value 0
Creating row #24 Colm# 4 value 0
Creating row #24 Colm# 5 value 0
Creating row #24 Colm# 6 value 0
Creating row #24 Colm# 7 value 0
Creating row #25 Colm# 1 value 22/Nov/2015
Creating row #25 Colm# 2 value 0
Creating row #25 Colm# 3 value 0
Creating row #25 Colm# 4 value 0
Creating row #25 Colm# 5 value 0
Creating row #25 Colm# 6 value 0
Creating row #25 Colm# 7 value 0
Creating row #26 Colm# 1 value 23/Nov/2015
Creating row #26 Colm# 2 value 0
Creating row #26 Colm# 3 value 0
Creating row #26 Colm# 4 value 0
Creating row #26 Colm# 5 value 0
Creating row #26 Colm# 6 value 0
Creating row #26 Colm# 7 value 0
Creating row #27 Colm# 1 value 24/Nov/2015
Creating row #27 Colm# 2 value 0
Creating row #27 Colm# 3 value 0
Creating row #27 Colm# 4 value 0
Creating row #27 Colm# 5 value 0
Creating row #27 Colm# 6 value 0
Creating row #27 Colm# 7 value 0
Creating row #28 Colm# 1 value 25/Nov/2015
Creating row #28 Colm# 2 value 0
Creating row #28 Colm# 3 value 0
Creating row #28 Colm# 4 value 0
Creating row #28 Colm# 5 value 0
Creating row #28 Colm# 6 value 0
Creating row #28 Colm# 7 value 0
Creating row #29 Colm# 1 value 26/Nov/2015
Creating row #29 Colm# 2 value 0
Creating row #29 Colm# 3 value 0
Creating row #29 Colm# 4 value 0
Creating row #29 Colm# 5 value 0
Creating row #29 Colm# 6 value 0
Creating row #29 Colm# 7 value 0
Creating row #30 Colm# 1 value 27/Nov/2015
Creating row #30 Colm# 2 value 0
Creating row #30 Colm# 3 value 0
Creating row #30 Colm# 4 value 0
Creating row #30 Colm# 5 value 0
Creating row #30 Colm# 6 value 0
Creating row #30 Colm# 7 value 0
Creating row #31 Colm# 1 value 28/Nov/2015
Creating row #31 Colm# 2 value 0
Creating row #31 Colm# 3 value 0
Creating row #31 Colm# 4 value 0
Creating row #31 Colm# 5 value 0
Creating row #31 Colm# 6 value 0
Creating row #31 Colm# 7 value 0
Creating row #32 Colm# 1 value 29/Nov/2015
Creating row #32 Colm# 2 value 0
Creating row #32 Colm# 3 value 0
Creating row #32 Colm# 4 value 0
Creating row #32 Colm# 5 value 0
Creating row #32 Colm# 6 value 0
Creating row #32 Colm# 7 value 0
Creating row #33 Colm# 1 value 30/Nov/2015
Creating row #33 Colm# 2 value 0
Creating row #33 Colm# 3 value 0
Creating row #33 Colm# 4 value 0
Creating row #33 Colm# 5 value 0
Creating row #33 Colm# 6 value 0
Creating row #33 Colm# 7 value 0
***end****
***start****
name YUVRAJ VERMA token:A1539 category:D depart:14 month:11 year:2015
Creating row #1 Colm# 8 value YUVRAJ VERMA
Creating row #2 Colm# 8 value A1539
Creating row #3 Colm# 8 value R
Creating row #3 Colm# 9 value W
Creating row #3 Colm# 10 value FH
Creating row #3 Colm# 11 value OT-R
Creating row #3 Colm# 12 value OT-W
Creating row #3 Colm# 13 value OT-FH
Creating row #4 Colm# 8 value 2
Creating row #4 Colm# 9 value 0
Creating row #4 Colm# 10 value 3
Creating row #4 Colm# 11 value 0
Creating row #4 Colm# 12 value 3
Creating row #4 Colm# 13 value 0
Creating row #5 Colm# 8 value 0
Creating row #5 Colm# 9 value 0
Creating row #5 Colm# 10 value 0
Creating row #5 Colm# 11 value 4
Creating row #5 Colm# 12 value 0
Creating row #5 Colm# 13 value 0
Creating row #6 Colm# 8 value 3
Creating row #6 Colm# 9 value 0
Creating row #6 Colm# 10 value 0
Creating row #6 Colm# 11 value 0
Creating row #6 Colm# 12 value 0
Creating row #6 Colm# 13 value 0
Creating row #7 Colm# 8 value 0
Creating row #7 Colm# 9 value 68
Creating row #7 Colm# 10 value 8
Creating row #7 Colm# 11 value 0
Creating row #7 Colm# 12 value 0
Creating row #7 Colm# 13 value 0
Creating row #8 Colm# 8 value 0
Creating row #8 Colm# 9 value 0
Creating row #8 Colm# 10 value 0
Creating row #8 Colm# 11 value 0
Creating row #8 Colm# 12 value 0
Creating row #8 Colm# 13 value 0
Creating row #9 Colm# 8 value 0
Creating row #9 Colm# 9 value 0
Creating row #9 Colm# 10 value 0
Creating row #9 Colm# 11 value 0
Creating row #9 Colm# 12 value 0
Creating row #9 Colm# 13 value 0
Creating row #10 Colm# 8 value 0
Creating row #10 Colm# 9 value 0
Creating row #10 Colm# 10 value 0
Creating row #10 Colm# 11 value 0
Creating row #10 Colm# 12 value 0
Creating row #10 Colm# 13 value 0
Creating row #11 Colm# 8 value 0
Creating row #11 Colm# 9 value 0
Creating row #11 Colm# 10 value 0
Creating row #11 Colm# 11 value 0
Creating row #11 Colm# 12 value 0
Creating row #11 Colm# 13 value 0
Creating row #12 Colm# 8 value 0
Creating row #12 Colm# 9 value 0
Creating row #12 Colm# 10 value 0
Creating row #12 Colm# 11 value 0
Creating row #12 Colm# 12 value 0
Creating row #12 Colm# 13 value 0
Creating row #13 Colm# 8 value 0
Creating row #13 Colm# 9 value 0
Creating row #13 Colm# 10 value 0
Creating row #13 Colm# 11 value 0
Creating row #13 Colm# 12 value 0
Creating row #13 Colm# 13 value 0
Creating row #14 Colm# 8 value 0
Creating row #14 Colm# 9 value 0
Creating row #14 Colm# 10 value 0
Creating row #14 Colm# 11 value 0
Creating row #14 Colm# 12 value 0
Creating row #14 Colm# 13 value 0
Creating row #15 Colm# 8 value 0
Creating row #15 Colm# 9 value 0
Creating row #15 Colm# 10 value 0
Creating row #15 Colm# 11 value 0
Creating row #15 Colm# 12 value 0
Creating row #15 Colm# 13 value 0
Creating row #16 Colm# 8 value 0
Creating row #16 Colm# 9 value 0
Creating row #16 Colm# 10 value 0
Creating row #16 Colm# 11 value 0
Creating row #16 Colm# 12 value 0
Creating row #16 Colm# 13 value 0
Creating row #17 Colm# 8 value 0
Creating row #17 Colm# 9 value 0
Creating row #17 Colm# 10 value 0
Creating row #17 Colm# 11 value 0
Creating row #17 Colm# 12 value 0
Creating row #17 Colm# 13 value 0
Creating row #18 Colm# 8 value 0
Creating row #18 Colm# 9 value 0
Creating row #18 Colm# 10 value 0
Creating row #18 Colm# 11 value 0
Creating row #18 Colm# 12 value 0
Creating row #18 Colm# 13 value 0
Creating row #19 Colm# 8 value 0
Creating row #19 Colm# 9 value 0
Creating row #19 Colm# 10 value 0
Creating row #19 Colm# 11 value 0
Creating row #19 Colm# 12 value 0
Creating row #19 Colm# 13 value 0
Creating row #20 Colm# 8 value 0
Creating row #20 Colm# 9 value 0
Creating row #20 Colm# 10 value 0
Creating row #20 Colm# 11 value 0
Creating row #20 Colm# 12 value 0
Creating row #20 Colm# 13 value 0
Creating row #21 Colm# 8 value 0
Creating row #21 Colm# 9 value 0
Creating row #21 Colm# 10 value 0
Creating row #21 Colm# 11 value 0
Creating row #21 Colm# 12 value 0
Creating row #21 Colm# 13 value 0
Creating row #22 Colm# 8 value 0
Creating row #22 Colm# 9 value 0
Creating row #22 Colm# 10 value 0
Creating row #22 Colm# 11 value 0
Creating row #22 Colm# 12 value 0
Creating row #22 Colm# 13 value 0
Creating row #23 Colm# 8 value 0
Creating row #23 Colm# 9 value 0
Creating row #23 Colm# 10 value 0
Creating row #23 Colm# 11 value 0
Creating row #23 Colm# 12 value 0
Creating row #23 Colm# 13 value 0
Creating row #24 Colm# 8 value 0
Creating row #24 Colm# 9 value 0
Creating row #24 Colm# 10 value 0
Creating row #24 Colm# 11 value 0
Creating row #24 Colm# 12 value 0
Creating row #24 Colm# 13 value 0
Creating row #25 Colm# 8 value 0
Creating row #25 Colm# 9 value 0
Creating row #25 Colm# 10 value 0
Creating row #25 Colm# 11 value 0
Creating row #25 Colm# 12 value 0
Creating row #25 Colm# 13 value 0
Creating row #26 Colm# 8 value 0
Creating row #26 Colm# 9 value 0
Creating row #26 Colm# 10 value 0
Creating row #26 Colm# 11 value 0
Creating row #26 Colm# 12 value 0
Creating row #26 Colm# 13 value 0
Creating row #27 Colm# 8 value 0
Creating row #27 Colm# 9 value 0
Creating row #27 Colm# 10 value 0
Creating row #27 Colm# 11 value 0
Creating row #27 Colm# 12 value 0
Creating row #27 Colm# 13 value 0
Creating row #28 Colm# 8 value 0
Creating row #28 Colm# 9 value 0
Creating row #28 Colm# 10 value 0
Creating row #28 Colm# 11 value 0
Creating row #28 Colm# 12 value 0
Creating row #28 Colm# 13 value 0
Creating row #29 Colm# 8 value 0
Creating row #29 Colm# 9 value 0
Creating row #29 Colm# 10 value 0
Creating row #29 Colm# 11 value 0
Creating row #29 Colm# 12 value 0
Creating row #29 Colm# 13 value 0
Creating row #30 Colm# 8 value 0
Creating row #30 Colm# 9 value 0
Creating row #30 Colm# 10 value 0
Creating row #30 Colm# 11 value 0
Creating row #30 Colm# 12 value 0
Creating row #30 Colm# 13 value 0
Creating row #31 Colm# 8 value 0
Creating row #31 Colm# 9 value 0
Creating row #31 Colm# 10 value 0
Creating row #31 Colm# 11 value 0
Creating row #31 Colm# 12 value 0
Creating row #31 Colm# 13 value 0
Creating row #32 Colm# 8 value 0
Creating row #32 Colm# 9 value 0
Creating row #32 Colm# 10 value 0
Creating row #32 Colm# 11 value 0
Creating row #32 Colm# 12 value 0
Creating row #32 Colm# 13 value 0
Creating row #33 Colm# 8 value 0
Creating row #33 Colm# 9 value 0
Creating row #33 Colm# 10 value 0
Creating row #33 Colm# 11 value 0
Creating row #33 Colm# 12 value 0
Creating row #33 Colm# 13 value 0
***end****

调用上述代码的代码如下:

            try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/nmdckdl" ,
"root" , "" );
//connection = DBUtility.getConnection();
Statement statement = connection.createStatement();
workbook = new XSSFWorkbook();
FileOutputStream out = new FileOutputStream(new File("incentiveDetails.xlsx"));
XSSFSheet spreadsheet = workbook.createSheet("Individual Incentive");
XSSFRow row=spreadsheet.createRow(1);
/*Creating headers */
spreadsheet.addMergedRegion(new CellRangeAddress(
1, // mention first row here
3, //mention last row here, it is 1 as we are doing a column wise merging
1, //mention first column of merging
1 //mention last column to include in merge
));
createCell(workbook, row, (short) 1, CellStyle.ALIGN_CENTER_SELECTION, CellStyle.VERTICAL_CENTER,"Date");
int year,month;
String name,department,category,token;
year = 2015; month = 11;
String tempDt = year+"-"+month+"-01"; //yyyy-mm-dd
java.sql.Date date = valueOf(tempDt); //convert string date to java.sql.Date
ProductionDetailsDao production = new ProductionDetailsDao();
String oracleDate = production.javaSqlDateToString(date,"yyyy-MM-dd");
SimpleDateFormat oracleFormat = new SimpleDateFormat("yyyy-MM-dd");
String[] temp = oracleDate.split("-");
temp[2]= "__";
String temp2 = String.join("-", temp).toUpperCase();
ResultSet resultSet = statement.executeQuery("select name,token,cat,dep from indinc_t where dt like '"+ temp2 +"' group by token order by token asc");
List<ProductionDetailsBean> productionList = null;
int empCount =0,i=1;
while(resultSet.next()) {
row.setRowNum(1);
empCount++;
System.out.println("***start****");
name = resultSet.getString("Name");
token = resultSet.getString("Token");
category = resultSet.getString("Cat");
department = resultSet.getString("Dep");

System.out.println("name "+name+" token:"+token+" category:"+category + " depart:"+department+" month:"+month+ " year:"+year);
spreadsheet.addMergedRegion(new CellRangeAddress(1,1,i+1,i+6));

createCell(workbook, row, (short) (i+1), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_GENERAL,name);
row=spreadsheet.createRow(2);
spreadsheet.addMergedRegion(new CellRangeAddress(2,2, i+1,i+6));
createCell(workbook, row, (short) (i+1), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_GENERAL,token);
row=spreadsheet.createRow(3);
createCell(workbook, row, (short) (i+1), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_CENTER,"R");
createCell(workbook, row, (short) (i+2), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_CENTER,"W");
createCell(workbook, row, (short) (i+3), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_CENTER,"FH");
createCell(workbook, row, (short) (i+4), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_CENTER,"OT-R");
createCell(workbook, row, (short) (i+5), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_CENTER,"OT-W");
createCell(workbook, row, (short) (i+6), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.ALIGN_CENTER,"OT-FH");
ProductionDetailsDao prodDao = new ProductionDetailsDao();
ProductionDetailsBean prod;
productionList = new ArrayList();
PreparedStatement ps = null;
token = token.toUpperCase();
String data,query ;
int rom,waste,fh,otrom,otwaste,otfh;
try {
query = "SELECT * from indinc_t WHERE upper(token) = ? and dep = ? and cat = ? and dt like ? order by dt";
ps = connection.prepareStatement(query);
if(ps == null){
System.out.println("Error in setting preparerd statement...");
} else {
ps.setString(1, token.toUpperCase());
ps.setString(2, department.toUpperCase());
ps.setString(3, category.toUpperCase());
ps.setString(4, temp2);
ResultSet rs = ps.executeQuery();
int r= 3;
while (rs.next()) {
prod = new ProductionDetailsBean();
rom = rs.getInt("ROM");
waste = rs.getInt("WASTE");
fh = rs.getInt("FHR");
otrom = rs.getInt("ROM85");
otwaste = rs.getInt("WASTE85");
otfh = rs.getInt("FHR85");
date = rs.getDate("DT");// Date received in format yyyy-mm-dd java.sql.Date
System.out.println("date is "+date);
String strDt="";
if( date !=null ) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy");
strDt = sdf.format(date);
}
r++;
row=spreadsheet.createRow(r);
if(empCount == 1) {
createCell(workbook, row, (short) empCount, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER,strDt);
}

createCell(workbook, row, (short) (i+1), CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER,rom);
createCell(workbook, row, (short) (i+2), CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER,waste);
createCell(workbook, row, (short) (i+3), CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER,fh);
createCell(workbook, row, (short) (i+4), CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER,otrom);
createCell(workbook, row, (short) (i+5), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.VERTICAL_CENTER,otwaste);
createCell(workbook, row, (short) (i+6), CellStyle.ALIGN_CENTER_SELECTION, CellStyle.VERTICAL_CENTER,otfh);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
i=i+6;
System.out.println("***end****");
}

workbook.write(out);
out.close();
System.out.println("incentive details.xlsx written successfully");
}
catch (SQLException ex) {
System.out.println(ex.getMessage());
Logger.getLogger(DownloadExcel.class.getName()).log(Level.SEVERE, null, ex);
}

最佳答案

你不应该打电话

row.setRowNum(1);

spreadsheet.createRow

在这种循环中。第一个调用没有意义,第二个调用将覆盖您在上一个循环迭代中已经创建的行。相反,应在循环之前创建行,然后使用 spreadsheet.getRow 在循环内检索它们。

关于java - Apache POI 未在 Excel 中为每一列呈现输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34529816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com