用循环更新Excel文件

首先,感谢您能给我的所有答案。

我的问题似乎也许很容易,但我是一个Java初学者。 我必须用某个date更新我的Excel文件。 但是,所有的信息都发送到循环结束时的Excel表格,而不是在循环中。

private void calculateExcelStaffingHistoriqueStockDetail(final List<StockVo> listStock, final WritableSheet sheet, boolean isMois, int jourD, int moisD, int anneeD, int taillePeriode) throws WriteException { // Set Excel cell format header //final String[] tabDomaine = { "Aucun Domaine", "Contrat/Produit", "Comptabilité", "Rég.Finance", "Sinistre", "Interface" }; // Create a cell format for Arial 10 point font final WritableFont arial10font = new WritableFont(WritableFont.ARIAL, 10); final WritableCellFormat arial10format = new WritableCellFormat(arial10font); arial10format.setBorder(Border.ALL, BorderLineStyle.THIN); for (int row = 0; row < listStock.size(); row++) { final StockVo stock = listStock.get(row); String ch = ""; int i = 0; // Vue Mensuel if (isMois) { for (i = moisD; i < taillePeriode + moisD; i++) { if (i <= 12) { if (i < 10) { ch = "0" + i + "/" + anneeD; } else { ch = i + "/" + anneeD; } } else { i = i - 12; if (i < 10) { ch = "0" + (i - 12) + "/" + (anneeD + 1); } else { ch = (i - 12) + "/" + (anneeD + 1); } } sheet.addCell(new Label(3 + row, 6, ch, arial10format)); } // Le totaux des entrees, livraisons, stock et en attentes de tout les domaines sheet.addCell(new Label(1, 7, "Total", arial10format)); sheet.addCell(new Label(2, 7, "Total", arial10format)); sheet.addCell(new Label(2, 8, "Stock", arial10format)); sheet.addCell(new Label(2, 9, "En Attentes", arial10format)); sheet.addCell(new Label(2, 10, "Entrées", arial10format)); sheet.addCell(new Label(2, 11, "Sortie", arial10format)); sheet.addCell(new Label(3 + row, 7, Integer.toString(stock.getStock() + stock.getAttentes() + stock.getEntrees() + stock.getLivraisons()), arial10format)); sheet.addCell(new Label(3 + row, 8, Integer.toString(stock.getStock()), arial10format)); sheet.addCell(new Label(3 + row, 9, Integer.toString(stock.getAttentes()), arial10format)); sheet.addCell(new Label(3 + row, 10, Integer.toString(stock.getEntrees()), arial10format)); sheet.addCell(new Label(3 + row, 11, Integer.toString(stock.getLivraisons()), arial10format)); } } } 

所以我想更新我在不同的单元格中select的date。 所以如果我select4个月,我必须有01/01/17,01/02/17,01/03/17,01/04/17。

但其实我有这个:01/01 / 17,01 / 1 / 17,01 / 1 / 17,01 / 1/17。

你知道为什么“sheet.addCell(new Label(3 + row,6,ch,arial10format));” 是在最后更新,而不是每次都拿起不同的date? (PS:在debugging模式下,信息是正确选取的,问题是当我必须把它发送到Excel工作表时,它只发送最后4个date而不是1个date4次。