From 5d91a329768a2a86e01e4b9b6bc6a2b939b87adb Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期五, 16 一月 2026 22:48:51 +0800
Subject: [PATCH] 修改了对应代码
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java | 242 ++++++++++++++++++++++++++++++++++++++----------
1 files changed, 191 insertions(+), 51 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
index 4c5a8de..772777f 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
@@ -307,7 +307,6 @@
int column = 0;
if(index == 0) {
// 鍚堝苟绗竴琛岀殑鍓�5涓崟鍏冩牸
- sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 8));
// 蹇呴』鍏堣缃负true
// 椤甸潰甯冨眬璁剧疆
@@ -323,7 +322,7 @@
// 鍏朵粬鎵撳嵃璁剧疆
printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); // A4绾�
- printSetup.setLandscape(false); // 绾靛悜鎵撳嵃
+ printSetup.setLandscape(true); // 绾靛悜鎵撳嵃
// 鍒涘缓琛屽苟璁剧疆楂樺害
@@ -331,35 +330,51 @@
//鐢熸垚浜岀淮鐮�
if(includeQrCode)
{
- row.setHeight((short)(40 * 40));
+ row.setHeight((short)(55.8 * 20));
- Cell cell = row.createCell(6);
+ Cell cell = row.createCell(0);
+// for(int cl = 1 ; cl <=8; cl++)
+// cell = row.createCell(cl);
+//
+//
+// for (int col = 4; col <= 7; col++) {
+// row.getSheet().setColumnWidth(col, 15 * 256); // 姣忓垪15瀛楃瀹�
+ // }
+
+ int margin = -40* 9525;
+ int mary = -11 * 9525;
+ XSSFClientAnchor anchor = new XSSFClientAnchor(
+ 0, // dx1
+ 0, // dy1
+ margin, // dx2锛氬彸杈圭晫宸︾Щ10鍍忕礌
+ mary, // dy2
+ (short)5, // col1
+ 0, // row1
+ (short)9, // col2
+ 1 // row2
+ );
// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
- cell.getRow().getRowNum() + 1);
+ // ClientAnchor anchor = new XSSFClientAnchor(0, 0, 600, 150, (short)0, 0, (short)6, 1);
+ // anchor.setDx2(488);
+ // anchor.setDy2(10);
+ // anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
// 璁$畻灞呬腑浣嶇疆
-// int col1 = 0; // 涓棿鍒�
-// int col2 = col1 + 2;
-// anchor.setCol1(col1);
-// anchor.setCol2(col2);
-// anchor.setDx1(100);
-// anchor.setDy1(0);
-// anchor.setDx2(255); // 瀹藉害
-// anchor.setDy2(255); // 楂樺害
- anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
+
+
// 璁$畻灞呬腑浣嶇疆
- int col1 = 3; // 涓棿鍒�
- int col2 = col1 + 3;
- anchor.setCol1(col1);
- anchor.setCol2(col2);
- anchor.setRow1(0);
- anchor.setRow2(1);
+// int col1 = 4; // 涓棿鍒�
+// int col2 = col1 + 3;
+// anchor.setCol1(col1);
+// anchor.setCol2(col2);
+// anchor.setRow1(0);
+// anchor.setRow2(1);
+
byte[] data = bt;
// 鑾峰彇鍥剧墖鍘熷灏哄
BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
- double widthInEMU = image.getWidth() * 9525 * 0.2;
- double heightInEMU = image.getHeight() * 9525;
+// double widthInEMU = image.getWidth() * 9525 * 0.2;
+// double heightInEMU = image.getHeight() * 9525;
// 璁剧疆鍥剧墖鍘熷灏哄
// anchor.setDx2(-100000); // 鍘熷瀹藉害
@@ -377,14 +392,15 @@
row = sheet.createRow(firow);
}
else
- row.setHeight((short)(20 * 20));
+ row.setHeight((short)(33 * 20));
+ // sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 8));
// sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
if(firow==1)
{
sheet.addMergedRegion(new CellRangeAddress(firow, firow, 0, 8));
// 鍒涘缓琛屽苟璁剧疆楂樺害
- row.setHeight((short)(20 * 20));
+ row.setHeight((short)(33 * 20));
}
Cell titleCell = row.createCell(0);
titleCell.setCellValue("鏂囦欢鏉愭枡绉讳氦鐩綍娓呭崟(鍗峰唴绾�)");
@@ -392,62 +408,86 @@
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setBold(true);
+ font.setFontHeightInPoints((short) 18);
+
font.setFontName("瀹嬩綋");
style.setFont(font);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
titleCell.setCellStyle(style);
firow = firow + 1;
row = sheet.createRow(firow);
+
// 灏嗗浐瀹氳楂樻敼涓鸿嚜鍔ㄨ楂橈紝浠ヤ究鍐呭鑳藉畬鏁存樉绀哄湪鍚堝苟鍖哄煙
- row.setHeight((short)(50*20));
+ row.setHeight((short)(27.6*20));
//
CellStyle style1 = wb.createCellStyle();
- style1.setAlignment(HorizontalAlignment.LEFT);
+ style1.setAlignment(HorizontalAlignment.RIGHT);
+ style1.setVerticalAlignment(VerticalAlignment.TOP);
+ Font font1 = wb.createFont();
+ font1.setBold(true);
+ font1.setFontHeightInPoints((short) 12);
+
+ font1.setFontName("瀹嬩綋");
+ style1.setFont(font1);
Cell cell2 = row.createCell(0);
cell2.setCellValue("鍙戞枃鍙�:");
cell2.setCellStyle(style1);
-
+
// 鍚堝苟绗�1-3鍒�
int startCol1 = 1;
- int endCol1 = 3;
+ int endCol1 = 2;
sheet.addMergedRegion(new CellRangeAddress(firow, firow, startCol1, endCol1));
-
+
// 璁剧疆鎵�鏈夊悎骞跺崟鍏冩牸鐨勬牱寮�
for (int col = startCol1; col <= endCol1; col++) {
Cell mergedCell = row.createCell(col);
mergedCell.setCellStyle(style1);
}
-
+
// 鍙湪璧峰鍗曞厓鏍艰缃暟鎹�
+ CellStyle style2 = wb.createCellStyle();
+ style2.setAlignment(HorizontalAlignment.LEFT);
+ style2.setVerticalAlignment(VerticalAlignment.TOP);
+ Font font2 = wb.createFont();
+
+ font2.setFontHeightInPoints((short) 11);
+
+ font2.setFontName("瀹嬩綋");
+ style2.setFont(font2);
Cell inquiryCell = row.getCell(startCol1);
+ inquiryCell.setCellStyle(style2);
inquiryCell.setCellValue(inquiryNumber);
- Cell cell1 = row.createCell(4);
+ Cell cell1 = row.createCell(3);
cell1.setCellValue("妗堝嵎棰樺悕:");
cell1.setCellStyle(style1);
-
+
// 鍒涘缓涓�涓柊鐨勬牱寮忕敤浜庢鍗烽鍚嶅悎骞跺崟鍏冩牸
CellStyle mergedCellStyle = wb.createCellStyle();
mergedCellStyle.cloneStyleFrom(style1); // 缁ф壙鍘熸湁鏍峰紡
mergedCellStyle.setAlignment(HorizontalAlignment.LEFT); // 鏀逛负宸﹀榻�
mergedCellStyle.setWrapText(true); // 鍚敤鑷姩鎹㈣
//mergedCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 鍨傜洿灞呬腑
-
+
// 鍚堝苟绗�5-8鍒�
- int startCol = 5;
+ int startCol = 4;
int endCol = 8;
-
+
// 鍏堝垱寤烘墍鏈夐渶瑕佺殑鍗曞厓鏍煎苟璁剧疆鏍峰紡
for (int col = startCol; col <= endCol; col++) {
Cell mergedCell = row.createCell(col);
mergedCell.setCellStyle(mergedCellStyle);
}
-
+
// 鐒跺悗鎵ц鍚堝苟鎿嶄綔
sheet.addMergedRegion(new CellRangeAddress(firow, firow, startCol, endCol));
// 鍙湪璧峰鍗曞厓鏍艰缃暟鎹�
Cell getCas = row.getCell(startCol);
- getCas.setCellStyle(mergedCellStyle);
+
+ style2.setWrapText(true); // 鍚敤鑷姩鎹㈣
+
+ getCas.setCellStyle(style2);
getCas.setCellValue(caseTitle);
// 鍙湪璧峰鍗曞厓鏍艰缃暟鎹�
//ces.setCellValue(caseTitle);
@@ -463,6 +503,11 @@
// row.createCell(0).setCellValue("妗堝嵎棰樺悕:");
firow = firow + 1;
row = sheet.createRow(firow);
+
+
+
+ // 璁剧疆琛ㄥご楂樺害涓�43.2
+ row.setHeight((short)(43.2*20));
System.out.println("++++++++++++++++++++++++++---------++++++++++++");
System.out.println(firow);
column = 0;
@@ -470,6 +515,8 @@
// 鏅�歴heet澶勭悊
// recordId = (DocumentMaterialsVo)list.get(0)
row = sheet.createRow(0);
+ // 璁剧疆琛ㄥご楂樺害涓�43.2
+ row.setHeight((short)(43.2*20));
column = 0;
}
// // 浜х敓涓�琛�
@@ -487,19 +534,46 @@
//鍐欏叆绛惧悕
System.out.println(list.get(0).getDataset().size()+"aaaaaaaaaaaaaaaaaaa0999");
row = sheet.createRow(list.get(0).getDataset().size()+4);
+ row = sheet.createRow(list.get(0).getDataset().size()+5);
+
//
+ CellStyle style4 = wb.createCellStyle();
+
+ Font font4 = wb.createFont();
+ font4.setBold(true);
+ font4.setFontHeightInPoints((short) 12);
+
+ font4.setFontName("瀹嬩綋");
+ style4.setFont(font4);
+
+
int in = 0 ;
- for(int i = 0; i < sigArr.size(); i++) {
- row.createCell(in).setCellValue(sigArr.get(i));
- in = in + 3;
+ for (String s : sigArr) {
+ Cell clr = row.createCell(in);
+
+
+ System.out.println(s);
+ clr.setCellStyle(style4);
+ clr.setCellValue(s);
+
+ in = in + 2;
}
+ System.out.println(in);
+
+ // row = sheet.createRow(0);
+ // row = sheet.createRow(list.get(0).getDataset().size() + 7);
+
//鍐欏叆娉ㄩ噴
for(int i = 0; i < arrAn.size();i++) {
- row = sheet.createRow(list.get(0).getDataset().size() + 5+i);
- int ri = list.get(0).getDataset().size() + 5+i;
+ // System.out.println(arrAn.get(i));
+ row = sheet.createRow(list.get(0).getDataset().size() + 7+i);
+ int ri = list.get(0).getDataset().size() + 7+i;
sheet.addMergedRegion(new CellRangeAddress(ri, ri, 0, 3));
+ if(i==0)
+ row.createCell(0).setCellValue("娉�: "+(i+1)+"銆�"+arrAn.get(i));
+ else
+ row.createCell(0).setCellValue(" "+(i+1)+"銆�"+arrAn.get(i));
- row.createCell(0).setCellValue(i+1+"銆�"+arrAn.get(i));
}
}
@@ -637,7 +711,7 @@
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = wb.createFont();
- dataFont.setFontName("Arial");
+ dataFont.setFontName("瀹嬩綋");
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put("data", style);
@@ -662,9 +736,9 @@
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
}*/
Font headerFont = wb.createFont();
- headerFont.setFontName("Arial");
- headerFont.setFontHeightInPoints((short) 10);
- headerFont.setBold(false);
+ headerFont.setFontName("瀹嬩綋");
+ headerFont.setFontHeightInPoints((short) 11);
+ headerFont.setBold(true);
headerFont.setColor(excel.headerColor().index);
style.setFont(headerFont);
headerStyles.put(key, style);
@@ -678,7 +752,7 @@
// 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
style.setWrapText(true);
Font totalFont = wb.createFont();
- totalFont.setFontName("Arial");
+ totalFont.setFontName("瀹嬩綋");
totalFont.setFontHeightInPoints((short) 10);
style.setFont(totalFont);
styles.put("total", style);
@@ -798,7 +872,7 @@
Cell cell = null;
try {
// 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
- row.setHeight((short) -1);
+ // row.setHeight((short) -1);
// 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
if (attr.isExport()) {
// 鍒涘缓cell
@@ -813,7 +887,13 @@
} else if (align == HorizontalAlignment.RIGHT) {
styleKey = "data3";
}
- cell.setCellStyle(styles.get(styleKey));
+ // 鑾峰彇骞朵慨鏀规牱寮�
+ CellStyle style = styles.get(styleKey);
+ Workbook workbook = row.getSheet().getWorkbook();
+ CellStyle newStyle = workbook.createCellStyle();
+ newStyle.cloneStyleFrom(style);
+ newStyle.setWrapText(true); // 鍏抽敭锛氬惎鐢ㄨ嚜鍔ㄦ崲琛�
+ cell.setCellStyle(newStyle);
// 鐢ㄤ簬璇诲彇瀵硅薄涓殑灞炴��
Object value = getTargetValue(vo, field, attr);
@@ -830,6 +910,7 @@
// 璁剧疆鍒楃被鍨�
setCellVo(value, attr, cell);
}
+ adjustRowHeightAfterSetValue(row, cell, value);
addStatisticsData(column, Convert.toStr(value), attr);
}
} catch (Exception e) {
@@ -837,7 +918,65 @@
}
return cell;
}
+ /**
+ * 璁剧疆鍊煎悗璋冩暣琛岄珮
+ */
+ private void adjustRowHeightAfterSetValue(Row row, Cell cell, Object value) {
+ if (value == null) return;
+ String text = value.toString();
+ Sheet sheet = row.getSheet();
+
+ // 1. 璁$畻鑷姩楂樺害锛堝熀浜庡唴瀹癸級
+ short autoHeight = calculateSimpleAutoHeight(text, cell);
+
+ // 2. 鑾峰彇褰撳墠琛岄珮
+ short currentHeight = row.getHeight();
+ if (currentHeight == -1) {
+ currentHeight = sheet.getDefaultRowHeight();
+ }
+
+ // 3. 浣跨敤杈冨ぇ鐨勯珮搴︼紙鑷姩璁$畻鐨勯珮搴︽垨褰撳墠楂樺害锛�
+ short baseHeight = (short) Math.max(currentHeight, autoHeight);
+ System.out.println(baseHeight+"aaaaaaaaatttttttt");
+ // 4. 鍦ㄥ熀纭�涓婂鍔犻澶栭珮搴︼紙100鍗曚綅 = 5鐐癸級
+ short extraHeight = 80;
+ short newHeight = (short) (baseHeight + extraHeight);
+
+ // 5. 闄愬埗鏈�澶ч珮搴�
+ short maxHeight = (short) 4000; // 100鐐�
+ row.setHeight((short) Math.min(maxHeight,newHeight));
+ }
+
+ /**
+ * 绠�鍖栫殑鑷姩楂樺害璁$畻
+ */
+ private short calculateSimpleAutoHeight(String text, Cell cell) {
+ if (text == null || text.isEmpty()) return 0;
+
+ Sheet sheet = cell.getSheet();
+ int colIndex = cell.getColumnIndex();
+
+ // 鑾峰彇鍒楀锛堝瓧绗︽暟锛�
+ int colWidthChars = sheet.getColumnWidth(colIndex) / 256;
+ if (colWidthChars <= 0) colWidthChars = 10;
+
+ // 璁$畻鏂囨湰琛屾暟
+ int lines = 1;
+ if (text.contains("\n")) {
+ // 鏈夋樉寮忔崲琛�
+ String[] parts = text.split("\n");
+ for (String part : parts) {
+ lines += Math.max(1, (int) Math.ceil(part.length() * 1.5 / colWidthChars));
+ }
+ } else {
+ // 鑷姩鎹㈣
+ lines = (int) Math.ceil(text.length() * 1.5 / colWidthChars);
+ }
+
+ // 姣忚楂樺害锛氬亣璁�18鐐癸紙360 POI鍗曚綅锛�
+ return (short) (lines * 360);
+ }
/**
* 璁剧疆鍗曞厓鏍兼彁绀�
*
@@ -1163,3 +1302,4 @@
+
--
Gitblit v1.9.1