sinat_33415638 于 2016.01.28 17:51 提问

``````想实现分日期累加求和并添加到excel中，   可是传到excel中的数据把每一天的数据都打出来了。帮忙看一下问题出在哪了？
double sum = 0;
double a = 0;
String cellValue = "";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
Date date = inputRow.getCell(
Integer.parseInt(source.getProperty("日期列")) - 1)
.getDateCellValue();
cellValue = formatter.format(date);
ArrayList<String> date1 = new ArrayList<String>();
ArrayList<Double> value1 = new ArrayList<Double>();
ArrayList<String> date2 = new ArrayList<String>();
ArrayList<Double> value2 = new ArrayList<Double>();
Integer.parseInt(source.getProperty("求和列")) - 1)
.getNumericCellValue());
for (int c = 0; c < date1.size(); c++) {
try {
if (date1.get(c).equals(date1.get(c + 1))) {
a = value1.get(c);
sum = a + sum;
} else {
a = value1.get(c);
sum = a + sum;
sum = 0.0;
}
} catch (Exception e) {
a = value1.get(c);
sum = a + sum;
}
}
for (int k = 0; k < date2.size(); k++) {
outputRow.createCell(14).setCellValue(value2.get(k));
outputRow.createCell(3).setCellValue(date2.get(k));
outputRow.createCell(4).setCellValue(date2.get(k));
}
}

for (i = o; i < lastnum; i++) {
Process p = new ProcessRow();
XSSFSheet sheet = sc.getSheetAt(0);
XSSFRow outputrow = sheet.createRow(j++);
}
}
``````

1个回答

caozhy      2016.01.28 18:13

sinat_33415638 我感觉我这个写法，循环内每次执行存的都是一个新的数组里，循环到下一次就跟这次的没关系了

sinat_33415638 我不知道key值，我写的这个方法为什么不行