From bcd62be27acf68adb54415f75b37f5e26d65c11b Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 07 五月 2025 10:34:44 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java | 70 ++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 1 deletions(-)
diff --git a/server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java b/server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java
index 670f20c..0b02a91 100644
--- a/server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java
+++ b/server/system_service/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.core.utils.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.poi.ss.usermodel.*;
@@ -359,7 +360,7 @@
/**
* 閰嶇疆鍗曞厓鏍艰竟妗�
*/
- private void configCellBorder (CellStyle style) {
+ private static void configCellBorder(CellStyle style) {
style.setBorderTop(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
@@ -428,4 +429,71 @@
private Field field;
}
+ /**
+ * 瀵煎嚭鍒版寚瀹氳緭鍑烘祦
+ * @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);
+ for (int i = 0; i < dataList.size(); i++) {
+ Cell cell = header.createCell(i);
+ cell.setCellValue(dataList.get(i).get(Constants.ZERO));
+ // 鍒楀璁剧疆
+ sheet.setColumnWidth(i, dataList.get(i).get(Constants.ZERO).length() * 2 * 256);
+ // 璁剧疆鍒楀ご鍗曞厓鏍�
+ cell.setCellStyle(hstyle);
+ }
+
+ //鎬昏鏁�
+ Integer rowSize = dataList.get(Constants.ZERO).size();
+ //鎬诲垪鏁�
+ Integer columnSize = dataList.size();
+ for (int i = 1; i < rowSize; i++) {
+ Row row = sheet.createRow(i);
+ for (int j = 0; j < columnSize; j++) {
+ Cell cell = row.createCell(j);
+ cell.setCellValue(dataList.get(j).get(i));
+ }
+ }
+ 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();
+ }
+ }
+ }
+ }
+
+ 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;
+ }
+
+
+
+
}
--
Gitblit v1.9.3