From 09a49f7cd53acba5261802daf491cf01a10f8d9b Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 13 五月 2025 09:40:06 +0800
Subject: [PATCH] 最新版本541200007
---
server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java | 90 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 89 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..c6f70ac 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,91 @@
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);
+ CellStyle hstyle = configHeaderCellStatic(sxssfWorkbook);
+ CellStyle rowStyle = configDataCellStatic(sxssfWorkbook);
+ for (int i = 0; i < dataList.size(); i++) {
+ Row row = sheet.createRow(i);
+ List<String> rowList = dataList.get(i);
+ for (int j = 0; j < rowList.size(); j++) {
+ Cell cell = row.createCell(j);
+ if(i==0&&j==0){
+ cell.setCellValue("鏁版嵁鏃ユ湡");
+ }else{
+ cell.setCellValue(rowList.get(j));
+ }
+
+ if(i==0){
+ sheet.setColumnWidth(i, rowList.get(i).length() * 2 * 256);
+ cell.setCellStyle(hstyle);
+ }else if(j==0){
+ cell.setCellStyle(rowStyle);
+ }
+ }
+ }
+ 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) 10);
+ style.setFont(font);
+ // 璁剧疆杈规
+ configCellBorder(style);
+ return style;
+ }
+
+
+ /**
+ * 閰嶇疆鏁版嵁鍗曞厓鏍�
+ */
+ private static CellStyle configDataCellStatic (SXSSFWorkbook workbook ) {
+ CellStyle configDataCellStyle = workbook.createCellStyle();
+ configDataCellStyle.setAlignment(HorizontalAlignment.CENTER);
+ configDataCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鑳屾櫙
+ configDataCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ configDataCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+ // 瀛椾綋
+ Font font = workbook.createFont();
+ font.setFontHeightInPoints((short) 10);
+
+ configDataCellStyle.setFont(font);
+ // 杈规
+ configCellBorder(configDataCellStyle);
+ configDataCellStyle.setWrapText(true);
+
+ return configDataCellStyle;
+ }
+
}
--
Gitblit v1.9.3