From 5be5c89210dbb626dbb87a81265ff8eef92979df Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期一, 15 十二月 2025 15:32:57 +0800
Subject: [PATCH] 修改了对应代码
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java | 59 ++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
index 62fdb18..105f862 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
@@ -295,7 +295,7 @@
// 鍒涘缓琛屽苟璁剧疆楂樺害
row = sheet.createRow(0);
- row.setHeight((short)(40 * 40));
+ row.setHeight((short)(30 *30));
// 鍒涘缓鍗曞厓鏍煎苟娣诲姞鍥剧墖
Cell cell = row.createCell(0);
@@ -307,8 +307,8 @@
ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 5),
cell.getRow().getRowNum() + 1);
// 璁$畻灞呬腑浣嶇疆
- int col1 = 1; // 涓棿鍒�
- int col2 = col1 + 5;
+ int col1 = 3; // 涓棿鍒�
+ int col2 = col1 + 2;
anchor.setCol1(col1);
anchor.setCol2(col2);
anchor.setRow1(0);
@@ -335,12 +335,13 @@
row = sheet.createRow(1);
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6));
Cell titleCell = row.createCell(0);
- titleCell.setCellValue("鍗峰唴鐩綍");
- // 璁剧疆鍔犵矖鍜屽眳涓牱寮�
+ titleCell.setCellValue("鍗� 鍐� 鐩� 褰�");
+ // 璁剧疆鍔犵矖銆佸畫浣撱��18鍙峰瓧浣撳拰灞呬腑鏍峰紡
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setBold(true);
font.setFontName("瀹嬩綋");
+ font.setFontHeightInPoints((short) 18);
style.setFont(font);
style.setAlignment(HorizontalAlignment.CENTER);
titleCell.setCellStyle(style);
@@ -508,21 +509,35 @@
style.setFont(dataFont);
styles.put("data", style);
- style = wb.createCellStyle();
- style.cloneStyleFrom(styles.get("data"));
- style.setAlignment(HorizontalAlignment.CENTER);
- style.setVerticalAlignment(VerticalAlignment.CENTER);
- style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
- style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
- Font headerFont = wb.createFont();
- headerFont.setFontName("Arial");
- headerFont.setFontHeightInPoints((short) 10);
- headerFont.setBold(true);
- headerFont.setColor(IndexedColors.WHITE.getIndex());
- style.setFont(headerFont);
- // 琛ㄥご涔熻缃嚜鍔ㄦ崲琛�
- style.setWrapText(true);
- styles.put("header", style);
+ // 鍒涘缓琛ㄥご鏍峰紡鏄犲皠锛屾牴鎹瓻xcel娉ㄨВ鍔ㄦ�佺敓鎴�
+ Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
+ for (Object[] os : fields)
+ {
+ Excel excel = (Excel) os[1];
+ String key = StringUtils.format("header_{}_{}_{}_{}", excel.headerColor(), excel.headerBackgroundColor(), excel.headerFontName(), excel.headerFontBold());
+ if (!headerStyles.containsKey(key))
+ {
+ style = wb.createCellStyle();
+ style.cloneStyleFrom(styles.get("data"));
+ style.setAlignment(HorizontalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 鏍规嵁娉ㄨВ璁剧疆琛ㄥご鑳屾櫙鑹� - 宸叉敞閲婏紝琛ㄥご涓嶆樉绀鸿儗鏅壊
+ /*if (excel.headerBackgroundColor() != IndexedColors.WHITE) {
+ style.setFillForegroundColor(excel.headerBackgroundColor().index);
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ }*/
+ // 璁剧疆琛ㄥご鑷姩鎹㈣
+ style.setWrapText(true);
+ Font headerFont = wb.createFont();
+ headerFont.setFontName(excel.headerFontName());
+ headerFont.setFontHeightInPoints((short) 10);
+ headerFont.setBold(excel.headerFontBold());
+ headerFont.setColor(excel.headerColor().index);
+ style.setFont(headerFont);
+ headerStyles.put(key, style);
+ }
+ }
+ styles.putAll(headerStyles);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
@@ -568,7 +583,9 @@
// 鍐欏叆鍒椾俊鎭�
cell.setCellValue(attr.name());
setDataValidation(attr, row, column);
- cell.setCellStyle(styles.get("header"));
+ // 鏍规嵁Excel娉ㄨВ鍔ㄦ�侀�夋嫨琛ㄥご鏍峰紡
+ String key = StringUtils.format("header_{}_{}_{}_{}", attr.headerColor(), attr.headerBackgroundColor(), attr.headerFontName(), attr.headerFontBold());
+ cell.setCellStyle(styles.get(key));
return cell;
}
--
Gitblit v1.9.1