想实现分日期累加求和并添加到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>();
value1.add(inputRow.getCell(
Integer.parseInt(source.getProperty("求和列")) - 1)
.getNumericCellValue());
date1.add(cellValue);
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;
date2.add(date1.get(c));
value2.add(sum);
sum = 0.0;
}
} catch (Exception e) {
a = value1.get(c);
sum = a + sum;
date2.add(date1.get(c));
value2.add(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));
}
}
主函数里的方法,调用的processSum求和方法
for (i = o; i < lastnum; i++) {
XSSFRow readrow = readsheet.getRow(i);// 获取输入行
Process p = new ProcessRow();
if (p.panduan2(readrow)) {
XSSFSheet sheet = sc.getSheetAt(0);
XSSFRow outputrow = sheet.createRow(j++);
p.processSum(readrow, outputrow);
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
定义hashmap
,先循环,把相同日期的累加到相同日期为key
的数量中,然后再遍历输出,就是分组的结果了。