From 5de5db24efe1b25896c37f395124a207584bcb38 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期四, 01 一月 2026 21:25:54 +0800
Subject: [PATCH] 修改了对应代码

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java |  116 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 84 insertions(+), 32 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
index 287e7b0..e18f2be 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
@@ -14,7 +14,6 @@
 import com.ruoyi.common.utils.reflect.ReflectUtils;
 import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
 import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellRangeAddressList;
 import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
@@ -294,13 +293,37 @@
                 if(index==1)
                 {
                     Row row = sheet.createRow(0);
-                    row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
+                   // row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
+                    row.setHeight((short) (12.75*20));
                     int column = 0;
-                    row = sheet.createRow(0);
+                    row = sheet.createRow(1);
+                    row.setHeight((short) (12.75*20));
                     sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 1));
                     row = sheet.createRow(2);
-                    row.setHeightInPoints(100); // 璁剧疆琛岄珮涓�20纾�
+                    row.setHeight((short) (77.5*20));
+                    row = sheet.createRow(3);
+                    row.setHeight((short) (35*20));
+                    //   row.setHeightInPoints(100); // 璁剧疆琛岄珮涓�20纾�
 
+
+                    // 椤甸潰甯冨眬璁剧疆
+                    sheet.setAutobreaks(true);
+                    sheet.setFitToPage(true);
+
+                    // 鑾峰彇鎵撳嵃璁剧疆
+                    PrintSetup printSetup = sheet.getPrintSetup();
+
+                    // 璁剧疆涓�1椤靛搴�
+                    printSetup.setFitWidth((short) 1);   // 瀹藉害璋冩暣涓�1椤�
+                    printSetup.setFitHeight((short) 0);  // 楂樺害涓嶉檺鍒�
+
+                    // 鍏朵粬鎵撳嵃璁剧疆
+                    printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE);  // A4绾�
+                    printSetup.setLandscape(false);  // 绾靛悜鎵撳嵃
+                    sheet.setMargin(Sheet.LeftMargin, 1.04);
+                    sheet.setMargin(Sheet.RightMargin, 1.04);
+                    sheet.setMargin(Sheet.TopMargin, 0.97);
+                    sheet.setMargin(Sheet.BottomMargin, 0.97);
                     //鎷垮埌鍥剧墖
                     // 鍒涘缓鍗曞厓鏍煎苟娣诲姞鍥剧墖
                     Cell cell = row.createCell(0);
@@ -314,7 +337,9 @@
                         // 鍒涘缓鍗曞厓鏍�
                         Cell qrCell = sheet.createRow(2).createCell(1);
                         // 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず浜岀淮鐮�
-                        sheet.getRow(2).setHeightInPoints(100);
+                        sheet.getRow(2).setHeight((short) (77.5*20));
+                       // sheet.getRow(3).setHeight((short) (35*20));
+                      //  sheet.getRow(2).setHeightInPoints(100);
                         // 浜岀淮鐮侀渶瑕佽緝澶х殑鍒楀鏉ユ樉绀猴紝璁剧疆涔嬪墠鍏堜繚瀛樺綋鍓嶅垪瀹�
                         int currentColumnWidth = sheet.getColumnWidth(1);
                         // 璁剧疆瓒冲瀹界殑鍒楀浠ユ樉绀轰簩缁寸爜
@@ -323,7 +348,7 @@
                         // 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�2琛岀2鍒�
                         // 浜岀淮鐮佹樉绀哄湪鍙充笂瑙掍笖涓嶅~婊℃暣涓牸瀛�
                         // 缂╁皬鍥剧墖鑼冨洿锛氬彧鍗犵敤閮ㄥ垎鍗曞厓鏍肩┖闂�
-                        ClientAnchor anchor = new HSSFClientAnchor(700, 20, 1000, 220, (short) 1, 2, (short) 1, 2);
+                        ClientAnchor anchor = new HSSFClientAnchor(680, 0, 1000, 250, (short) 1, 2, (short) 1, 2);
                         // 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏�
                         anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);
                         
@@ -336,12 +361,13 @@
 
 
 
+
                     // 浠�"妗f棣� (瀹�) 鍙�:"涓哄熀鍑嗭紝缁熶竴鎵�鏈夋爣棰樼殑闀垮害鍜屾牸寮�
                     String [] tits = {
-                              "妗�                    鍙�:",
-                              "妗f棣�  (瀹�)  鍙�:",
-                               "缂�        寰�        鍙�:",
-                              "鍙�        鏂�        鍙�:",
+                              "妗�                     鍙�:",
+                              "妗f棣� 锛堝锛� 鍙�:",
+                               "缂�         寰�        鍙�:",
+                              "鍙�         鏂�        鍙�:",
                               "妗�     鍗�    棰�    鍚�:",
                               "缂�     鍒�    鏃�    鏈�:",
                               "缂�     鍒�    鍗�    浣�:",
@@ -366,10 +392,13 @@
                          Object fieldValue = field1.get(obj);
                          if(fieldValue==null)
                              fieldValue="";
+
                          if(i <= 3)
                             row = sheet.createRow(i+4);
                          if(i > 3)
                              row = sheet.createRow(i+7);
+                        if(i != 4)
+                            row.setHeight((short) (35*20));
                        // row.setHeight((short) 30);
                         // 涓嶈缃浐瀹氳楂橈紝鍚庣画浣跨敤autoSizeRow鑷姩璋冩暣
                         cell = row.createCell(0);
@@ -377,8 +406,8 @@
                         // 绗竴鍒楀搴﹁缃负27
                         // 绗簩鍒楀搴﹁缃负51
                         // 浣跨敤涓巃ddCell鏂规硶鐩稿悓鐨勮绠楀叕寮忚缃垪瀹�
-                        sheet.setColumnWidth(0, (int) ((29 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
-                        sheet.setColumnWidth(1, (int) ((52 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
+                        sheet.setColumnWidth(0, (int) ((27.86 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
+                        sheet.setColumnWidth(1, (int) ((51.57 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
 
                         CellStyle style = wb.createCellStyle();
                         style.setAlignment(HorizontalAlignment.RIGHT);
@@ -392,11 +421,20 @@
                         font.setFontHeightInPoints((short) 18);
                         style.setFont(font);
                         style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+
+                        if(i==4)
+                        {
+                            style.setVerticalAlignment(VerticalAlignment.TOP); // 璁剧疆鍨傜洿涓嬪榻�
+
+                        }
                         cell.setCellStyle(style);
                         cell.setCellValue(tits[i]);
+
+
                         Cell cel = row.createCell(1);
                         CellStyle style1 = wb.createCellStyle();
-                        style1.setBorderBottom(BorderStyle.THIN); // 娣诲姞涓嬪垝绾�
+                        if(i!=4)
+                            style1.setBorderBottom(BorderStyle.THIN); // 娣诲姞涓嬪垝绾�
                         style1.setWrapText(true); // 璁剧疆鑷姩鎹㈣
                         style1.setVerticalAlignment(VerticalAlignment.BOTTOM); // 璁剧疆鍨傜洿涓嬪榻�
 
@@ -416,8 +454,16 @@
                         {
                             // 纭繚妗�     鍗�    棰�    鍚�:杩欎竴琛岃兘鏍规嵁鍐呭闀垮害鑷姩鎹㈣
                             style1.setWrapText(true); // 鏄庣‘璁剧疆鑷姩鎹㈣
+                            style1.setVerticalAlignment(VerticalAlignment.TOP); // 璁剧疆鍨傜洿涓嬪榻�
+
                             cel.setCellStyle(style1);
+                            row.setHeight((short) (110*20));
+
+
+
+
                         }
+
                         // 澶勭悊鏃ユ湡鏍煎紡鍖栵紝鐗瑰埆鏄�"缂�  鍒�  鏃�  鏈�:"杩欎竴琛�
                         if (i == 5 && fieldValue instanceof Date) {
                             // 璁剧疆鏃ユ湡鏍煎紡涓簓yyy-MM-dd
@@ -428,29 +474,32 @@
                         }
 
                         // 瀵逛簬i==4鐨勬儏鍐碉紝纭繚琛岄珮鑳芥牴鎹唴瀹硅嚜鍔ㄨ皟鏁�
-                        if(i==4)
-                        {
-                            // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
-                            row.setHeight((short) -1);
-                            // 涓嶉檺鍒舵渶澶ц楂橈紝鍏佽鏍规嵁鍐呭鑷姩璋冩暣
-                        } else {
-                            // 浣跨敤setHeight鏂规硶璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
-                            row.setHeight((short) -1);
-                            // 纭繚琛岄珮鑷冲皯涓�40纾咃紝浣嗕笉闄愬埗鏈�澶ц楂�
-                            if (row.getHeightInPoints() < 40) {
-                                row.setHeightInPoints(40);
-                            }
-                        }
+//                        if(i==4)
+//                        {
+//                            // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
+//                          //  row.setHeight((short) -1);
+//                            // 涓嶉檺鍒舵渶澶ц楂橈紝鍏佽鏍规嵁鍐呭鑷姩璋冩暣
+//                        } else if (i > 4) { // 鍙i>1鐨勮搴旂敤杩欎簺璁剧疆锛屼繚鐣檌<=1鐨勮楂樿缃�
+//                            // 浣跨敤setHeight鏂规硶璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
+//                            row.setHeight((short) -1);
+//                            // 纭繚琛岄珮鑷冲皯涓�40纾咃紝浣嗕笉闄愬埗鏈�澶ц楂�
+//                            if (row.getHeightInPoints() < 40) {
+//                                row.setHeightInPoints(40);
+//                            }
+//                        }
                       //  sheet.setColumnWidth(0, 60 * 256);
                         i++;
                         if(i==3)
                         {
                             row = sheet.createRow(8);
+                            row.setHeight((short) (35*20));
                             // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
-                            row.setHeight((short) -1);
+                        //    row.setHeight((short) -1);
                             // row.setHeight((short) 30);
-                            row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
+                          //  row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
                             row = sheet.createRow(9);
+                            row.setHeight((short) (50*20));
+
                             //璁剧疆鏉″舰鐮�
                             // 璁剧疆鏉″舰鐮�
                             byte[] dat = list.get(index).getImgr();
@@ -458,7 +507,8 @@
                                 // 鍒涘缓鍗曞厓鏍�
                                 Cell barcodeCell = sheet.createRow(9).createCell(0);
                                 // 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず鏉″舰鐮�
-                                sheet.getRow(9).setHeightInPoints(40);
+                              //  sheet.getRow(9).setHeightInPoints(40);
+                                sheet.getRow(9).setHeight((short) (50*20));
                                 // 璁剧疆鍒楀瓒冲瀹戒互鏄剧ず鏉″舰鐮侊紝鍏堜繚瀛樺綋鍓嶅垪瀹�
                                 int currentColumnWidth0 = sheet.getColumnWidth(0);
                                 sheet.setColumnWidth(0, 40 * 256);
@@ -467,7 +517,7 @@
                                 // 鏉″舰鐮佸眳涓笖涓嶈秴鍑虹浜屼釜鏍煎瓙
                                 // 璋冩暣缁撴潫鍒楃储寮曞拰浣嶇疆鍙傛暟
                                 // 澧炲姞dx1鍊硷紝浣挎潯褰㈢爜鏁翠綋鍚戝彸绉诲姩
-                                ClientAnchor anchor1 = new HSSFClientAnchor(660, 50, 900, 200, (short) 0, 9, (short) 1, 10);
+                                ClientAnchor anchor1 = new HSSFClientAnchor(660, 0, 900, 60, (short) 0, 9, (short) 1, 10);
                                 // 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏�
                                 anchor1.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);
 
@@ -482,9 +532,9 @@
 
 
 
-                            row.setHeightInPoints(70); // 璁剧疆琛岄珮涓�20纾�
+                            //row.setHeightInPoints(70); // 璁剧疆琛岄珮涓�20纾�
                             row = sheet.createRow(10);
-                            row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+                            row.setHeight((short) (35*20));
                         }
                         // 鎵撳嵃瀛楁鍚嶇О鍜屽��
                         System.out.println(fieldName + ": " + fieldValue);
@@ -1197,3 +1247,5 @@
 
 
 
+
+

--
Gitblit v1.9.1