使用循环更新 Excel 文件
update a Excel file with a loop
首先,感谢您能给我的所有答案。
我的问题似乎很简单,但我是 Java 的初学者。我必须用某个日期更新我的 Excel 文件。但是所有信息都在循环结束时发送到 excel sheet 而不是我在循环中。
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));
}
}
}
所以我想更新我在不同单元格中选择的日期。所以如果我选择 4 个月,我必须有 01/01/17、01/02/17、01/03/17、01/04/17。
但实际上我有这个:01/04/17、01/04/17、01/04/17、01/04/17。
您知道为什么 "sheet.addCell(new Label(3 + row, 6, ch, arial10format));" 在最后更新而不是每次都选择不同的日期吗? (PS:在调试模式下,信息是正确的,问题是当我必须将它发送到 Excel sheet 时,它只发送最后日期 4 次而不是1次约会4次。
对于那些你需要答案的人,这对我来说很好。
String ch = "";
for (int row = 0; row < listStock.size(); row++) {
final StockVo stock = listStock.get(row);
// Vue Mensuel
if (isMois) {
//for (int i = moisD; i < taillePeriode + moisD; i++) {
final int mois = (row % 12) + 1;
final int annee = row / 12;
if (mois <= 9) {
ch = "0" + mois + "/" + (anneeD + annee);
} else {
ch = mois + "/" + (anneeD + annee);
}
sheet.addCell(new Label(3 + row, 6, ch, arial10format));
首先,感谢您能给我的所有答案。
我的问题似乎很简单,但我是 Java 的初学者。我必须用某个日期更新我的 Excel 文件。但是所有信息都在循环结束时发送到 excel sheet 而不是我在循环中。
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));
}
}
}
所以我想更新我在不同单元格中选择的日期。所以如果我选择 4 个月,我必须有 01/01/17、01/02/17、01/03/17、01/04/17。
但实际上我有这个:01/04/17、01/04/17、01/04/17、01/04/17。
您知道为什么 "sheet.addCell(new Label(3 + row, 6, ch, arial10format));" 在最后更新而不是每次都选择不同的日期吗? (PS:在调试模式下,信息是正确的,问题是当我必须将它发送到 Excel sheet 时,它只发送最后日期 4 次而不是1次约会4次。
对于那些你需要答案的人,这对我来说很好。
String ch = "";
for (int row = 0; row < listStock.size(); row++) {
final StockVo stock = listStock.get(row);
// Vue Mensuel
if (isMois) {
//for (int i = moisD; i < taillePeriode + moisD; i++) {
final int mois = (row % 12) + 1;
final int annee = row / 12;
if (mois <= 9) {
ch = "0" + mois + "/" + (anneeD + annee);
} else {
ch = mois + "/" + (anneeD + annee);
}
sheet.addCell(new Label(3 + row, 6, ch, arial10format));