| | |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | @Service |
| | | public class ExcelService { |
| | |
| | | |
| | | //填充数据列,key是列日期. value是列数据 |
| | | AtomicInteger count = new AtomicInteger(); |
| | | dataListMap.forEach((key, value) -> { |
| | | //对dateKeySet按时间排序 |
| | | Stream<Date> dateKeySetSorted = dateKeySet.stream().sorted(Comparator.comparing(Date::getTime)); |
| | | dateKeySetSorted.forEach(key -> { |
| | | List<BattRealTimeDataHistory> value = dataListMap.get(key); |
| | | //第三行时间列填充 |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss"); |
| | | row2OfSheet4.createCell(count.get() + 1).setCellValue(format.format(key)); |
| | |
| | | for (int j = 1; j <= 108; j++) { //这个是行的遍历 |
| | | sheet4.getRow(j + 2).createCell(columnCount-1); |
| | | } |
| | | |
| | | /*for (int i = 0; i < columnCount; i++) { //这个是列的遍历 |
| | | if (i == columnCount - 1) { |
| | | //最后一列备注:全部填空 |
| | | row2OfSheet4.createCell(i + 1); |
| | | for (int j = 1; j <= 108; j++) { //这个是行的遍历 |
| | | sheet4.getRow(j + 2).createCell(i ); |
| | | } |
| | | } else { |
| | | //获取数据 |
| | | List<BattRealTimeDataHistory> list = battRTDataHisService.getFirstRecordListOfDay(tableListInDB.get(i), timeAgo); |
| | | list.sort(Comparator.comparing(BattRealTimeDataHistory::getMonNum)); |
| | | //第三行的时间列填充 |
| | | Date testStartTime = list.get(0).getTestStartTime(); |
| | | //获取年月 |
| | | String testMonth = DateUtil.YYYY_DOT_MM.format(testStartTime); |
| | | row2OfSheet4.createCell(i + 1).setCellValue(testMonth); |
| | | addStatistics(list, "vol", "res"); |
| | | for (int j = 1; j <= 108; j++) { //这个是行的遍历 |
| | | sheet4.getRow(j + 2).createCell(i + 1).setCellValue((list.get(j - 1).getMonVol())); |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | addGlobalStylesToAllCells(sheet4, workbook); |
| | | |