From 0e2161fd0a237ed9ddfbb2d4630a1b7451746848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E9=9B=AA=E4=BC=9F?= Date: Wed, 11 Sep 2024 11:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=91=E6=B5=8B=E5=B9=B3=E5=8F=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?util?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/business/utils/UnitExcelUtils.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/UnitExcelUtils.java diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/UnitExcelUtils.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/UnitExcelUtils.java new file mode 100644 index 0000000..34d1e0f --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/UnitExcelUtils.java @@ -0,0 +1,84 @@ +package com.ruoyi.business.utils; + +import com.ruoyi.business.mapper.HwAlarmInfoMapper; +import com.ruoyi.common.core.utils.DateUtils; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.http.HttpServletResponse; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; + +public class UnitExcelUtils { + @Autowired + private HwAlarmInfoMapper hwAlarmInfoMapper; + + public void exportAlarmInfos(HttpServletResponse response, HashMap> map) throws IOException { + Workbook bk = new XSSFWorkbook(); + for (Long aLong : map.keySet()) { + List list3 = map.get(aLong); + Sheet unitId = bk.createSheet(aLong.toString()); + int row = 0; + for (row = 0;row < list3.size();row++){ + if (row == 0){ + LinkedHashMap map1 = list3.get(row); + ArrayList list1 = new ArrayList<>(map1.keySet()); + int size = map1.keySet().size(); + int cellIndex = 0; + Row row1 = unitId.createRow(row); + Row row2 = unitId.createRow(row + 1); + for (cellIndex = 0;cellIndex < size;cellIndex++){ + String key = list1.get(cellIndex).toString(); + row1.createCell(cellIndex).setCellValue(key); + Object value = map1.get(key); + if (value instanceof String){ + row2.createCell(cellIndex).setCellValue((String) map1.get(key)); + }else if (value instanceof Long){ + row2.createCell(cellIndex).setCellValue((Long) map1.get(key)); + }else if(value instanceof Date){ + row2.createCell(cellIndex).setCellValue((Date) map.get(key)); + } + + } + }else { + LinkedHashMap map1 = list3.get(row); + ArrayList list1 = new ArrayList<>(map1.keySet()); + int size = map1.keySet().size(); + int cellIndex = 0; + Row row1 = unitId.createRow(row); + for (cellIndex = 0;cellIndex < size;cellIndex++){ + String key = list1.get(cellIndex).toString(); + Object value = map1.get(key); + if (value instanceof String){ + row1.createCell(cellIndex).setCellValue((String) map1.get(key)); + }else if (value instanceof Long){ + row1.createCell(cellIndex).setCellValue((Long) map1.get(key)); + } + else if(value instanceof Date){ + row1.createCell(cellIndex).setCellValue((Date) map.get(key)); + } + } + } + + } + + } + + + try { +// FileOutputStream stream = new FileOutputStream("告警信息"); + bk.write(response.getOutputStream()); + + } catch (Exception e) { + e.printStackTrace(); + } + bk.close(); + } +}