想实现分日期累加求和并添加到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);
}
}
小白求教,分日期求和问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- threenewbee 2016-01-28 10:13关注
定义hashmap,先循环,把相同日期的累加到相同日期为key的数量中,然后再遍历输出,就是分组的结果了。
解决 无用评论 打赏 举报
悬赏问题
- ¥15 outlook无法配置成功
- ¥15 Pwm双极模式H桥驱动控制电机
- ¥30 这是哪个作者做的宝宝起名网站
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换