From dd8998a8f7bbf8823dba5fc219a961883e34ef7d Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期二, 18 三月 2025 17:32:26 +0800 Subject: [PATCH] jtt808初始化 --- server/services/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java | 80 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 1 deletions(-) diff --git a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java index d2fac34..6358b59 100644 --- a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java +++ b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java @@ -2,6 +2,7 @@ import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; +import com.doumee.dao.business.model.Goodsorder; import lombok.AllArgsConstructor; import lombok.Data; import org.apache.poi.ss.usermodel.*; @@ -167,6 +168,54 @@ } } } + /** + * 瀵煎嚭鍒版寚瀹氳緭鍑烘祦 + * @param os 杈撳嚭娴� + */ + public static void exportList (List<List<String>> dataList ,String sheetName, OutputStream os) { + SXSSFWorkbook sxssfWorkbook; + try { + sxssfWorkbook = new SXSSFWorkbook(); + Sheet sheet = sxssfWorkbook.createSheet(sheetName); + // 鍒涘缓鍒楀ご + sheet.createFreezePane(0, 1); + Row header = sheet.createRow(0); + CellStyle hstyle = configHeaderCellStatic(sxssfWorkbook); + CellStyle cstyle = configCellStatic(sxssfWorkbook); + List<String> headerList =dataList.get(0); + for (int i = 0; i < headerList.size(); i++) { + Cell cell = header.createCell(i); + cell.setCellValue(headerList.get(i)); + // 鍒楀璁剧疆 + sheet.setColumnWidth(i, headerList.get(i).length() * 2 * 256); + // 璁剧疆鍒楀ご鍗曞厓鏍� + cell.setCellStyle(hstyle); + } + // 鍒涘缓鏁版嵁璁板綍 + for (int rowIndex = 1; rowIndex < dataList.size(); rowIndex++) { + Row row = sheet.createRow(rowIndex ); + List<String> rowList = dataList.get(rowIndex); + for (int i = 0; i < rowList.size(); i++) { + Cell cell = row.createCell(i); + cell.setCellValue(rowList.get(i)); + // 鍒楀璁剧疆 + cell.setCellStyle(cstyle); + } + } + sxssfWorkbook.write(os); + os.close(); + } catch (Exception e) { + throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } /** * 瀵煎嚭鑷冲搷搴旀祦 @@ -292,6 +341,35 @@ configCellBorder(style); cell.setCellStyle(style); } + private static CellStyle configHeaderCellStatic (SXSSFWorkbook workbook) { + CellStyle style = workbook.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + // 璁剧疆鑳屾櫙 + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + // 瀛椾綋 + Font font = workbook.createFont(); + font.setFontHeightInPoints((short) 12); + style.setFont(font); + // 璁剧疆杈规 + configCellBorder(style); + return style; + } + private static CellStyle configCellStatic (SXSSFWorkbook workbook) { + CellStyle style = workbook.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + // 璁剧疆鑳屾櫙 + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + // 瀛椾綋 + Font font = workbook.createFont(); + font.setFontHeightInPoints((short) 12); + style.setFont(font); + // 璁剧疆杈规 + configCellBorder(style); + return style; + } /** * 閰嶇疆鍒楀ご鍗曞厓鏍� */ @@ -332,7 +410,7 @@ /** * 閰嶇疆鍗曞厓鏍艰竟妗� */ - private void configCellBorder (CellStyle style) { + private static void configCellBorder (CellStyle style) { style.setBorderTop(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); style.setBorderBottom(BorderStyle.THIN); -- Gitblit v1.9.3