From f2f1274c7b51671d6d3b0b503f229da4657484f2 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期五, 19 十二月 2025 23:31:58 +0800
Subject: [PATCH] 修改了对应代码

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java |  130 +++++++++++++++++++++++++++++++++---------
 1 files changed, 101 insertions(+), 29 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 aa097a8..65859d0 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,21 +14,18 @@
 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;
 import org.apache.poi.hssf.usermodel.HSSFDataValidation;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
-import org.apache.poi.hssf.usermodel.HSSFDataValidation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -37,6 +34,7 @@
 import java.text.DecimalFormat;
 import java.util.*;
 import java.util.stream.Collectors;
+
 
 /**
  * Excel鐩稿叧澶勭悊
@@ -60,6 +58,14 @@
      * 瀵煎嚭绫诲瀷锛圗XPORT:瀵煎嚭鏁版嵁锛汭MPORT锛氬鍏ユā鏉匡級
      */
     private Excel.Type type;
+
+    public Workbook getWb() {
+        return wb;
+    }
+
+    public void setWb(Workbook wb) {
+        this.wb = wb;
+    }
 
     /**
      * 宸ヤ綔钖勫璞�
@@ -293,7 +299,7 @@
                     row = sheet.createRow(0);
                     sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 1));
                     row = sheet.createRow(2);
-                    row.setHeightInPoints(120); // 璁剧疆琛岄珮涓�20纾�
+                    row.setHeightInPoints(100); // 璁剧疆琛岄珮涓�20纾�
 
                     //鎷垮埌鍥剧墖
                     // 鍒涘缓鍗曞厓鏍煎苟娣诲姞鍥剧墖
@@ -308,11 +314,11 @@
                         // 鍒涘缓鍗曞厓鏍�
                         Cell qrCell = sheet.createRow(2).createCell(1);
                         // 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず浜岀淮鐮�
-                        sheet.getRow(2).setHeightInPoints(120);
+                        sheet.getRow(2).setHeightInPoints(100);
                         // 浜岀淮鐮侀渶瑕佽緝澶х殑鍒楀鏉ユ樉绀猴紝璁剧疆涔嬪墠鍏堜繚瀛樺綋鍓嶅垪瀹�
                         int currentColumnWidth = sheet.getColumnWidth(1);
                         // 璁剧疆瓒冲瀹界殑鍒楀浠ユ樉绀轰簩缁寸爜
-                        sheet.setColumnWidth(1, 60 * 256);
+                        sheet.setColumnWidth(1, 40 * 256);
                         
                         // 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�2琛岀2鍒�
                         // 浜岀淮鐮佹樉绀哄湪鍙充笂瑙掍笖涓嶅~婊℃暣涓牸瀛�
@@ -330,8 +336,17 @@
 
 
 
-                    String [] tits = {"妗�        鍙�:","妗f棣�(瀹�)鍙�:","缂�  寰�  鍙�: ","鍙�  鏂�  鍙�:",
-                            "妗�  鍗�  棰�  鍚�:","缂�  鍒�  鏃�  鏈�:","缂�  鍒�  鍗�  浣�:","淇�  绠�  鏈�  闄�:","瀵�     绾�:"};
+                    // 浠�"妗f棣� (瀹�) 鍙�:"涓哄熀鍑嗭紝缁熶竴鎵�鏈夋爣棰樼殑闀垮害鍜屾牸寮�
+                    String [] tits = {
+                              "妗�                    鍙�:",
+                              "妗f棣�  (瀹�)  鍙�:",
+                               "缂�        寰�        鍙�:",
+                              "鍙�        鏂�        鍙�:",
+                              "妗�     鍗�    棰�    鍚�:",
+                              "缂�     鍒�    鏃�    鏈�:",
+                              "缂�     鍒�    鍗�    浣�:",
+                              "淇�     绠�    鏈�    闄�:",
+                              "瀵�                     绾�:"};
 
                     List tmp = list.get(index).getDataset();
                     Object obj = tmp.get(0);
@@ -356,23 +371,25 @@
                          if(i > 3)
                              row = sheet.createRow(i+7);
                        // row.setHeight((short) 30);
-                        row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
-                       // row.createCell(0)
+                        // 涓嶈缃浐瀹氳楂橈紝鍚庣画浣跨敤autoSizeRow鑷姩璋冩暣
                         cell = row.createCell(0);
                         // 鏍规嵁鐢ㄦ埛闇�姹傝缃浜屽瓙琛ㄦ牸鐨勫垪瀹�
                         // 绗竴鍒楀搴﹁缃负27
                         // 绗簩鍒楀搴﹁缃负51
                         // 浣跨敤涓巃ddCell鏂规硶鐩稿悓鐨勮绠楀叕寮忚缃垪瀹�
-                        sheet.setColumnWidth(0, (int) ((27 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
-                        sheet.setColumnWidth(1, (int) ((51 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
+                        sheet.setColumnWidth(0, (int) ((29 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
+                        sheet.setColumnWidth(1, (int) ((52 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
 
                         CellStyle style = wb.createCellStyle();
                         style.setAlignment(HorizontalAlignment.RIGHT);
-                        style.setVerticalAlignment(VerticalAlignment.CENTER);
-style.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
-                      //  style.setAlignment(VerticalAlignment.CENTER);
+                        style.setVerticalAlignment(VerticalAlignment.BOTTOM); // 璁剧疆鍨傜洿涓嬪榻�
+                        style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+
+                        // 璁剧疆瀛椾綋涓篢imes New Roman 18鍙�
                         Font font = wb.createFont();
                         font.setBold(true);
+                        font.setFontName("Times New Roman");
+                        font.setFontHeightInPoints((short) 18);
                         style.setFont(font);
                         style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
                         cell.setCellStyle(style);
@@ -381,9 +398,26 @@
                         CellStyle style1 = wb.createCellStyle();
                         style1.setBorderBottom(BorderStyle.THIN); // 娣诲姞涓嬪垝绾�
                         style1.setWrapText(true); // 璁剧疆鑷姩鎹㈣
-                        style1.setVerticalAlignment(VerticalAlignment.CENTER);
+                        style1.setVerticalAlignment(VerticalAlignment.BOTTOM); // 璁剧疆鍨傜洿涓嬪榻�
+
+                        // 璁剧疆鍐呭瀛椾綋涓篢imes New Roman 16鍙�
+                        Font contentFont = wb.createFont();
+                        contentFont.setFontName("Times New Roman");
+                        contentFont.setFontHeightInPoints((short) 16);
+
+                        // 褰搃==4鏃讹紝涓烘枃瀛楁坊鍔犱笅鍒掔嚎
+                        if(i==4) {
+                            contentFont.setUnderline(Font.U_SINGLE); // 娣诲姞鍗曚笅鍒掔嚎
+                        }
+
+                        style1.setFont(contentFont);
                         cel.setCellStyle(style1);
-                        
+                        if(i==4)
+                        {
+                            // 纭繚妗�     鍗�    棰�    鍚�:杩欎竴琛岃兘鏍规嵁鍐呭闀垮害鑷姩鎹㈣
+                            style1.setWrapText(true); // 鏄庣‘璁剧疆鑷姩鎹㈣
+                            cel.setCellStyle(style1);
+                        }
                         // 澶勭悊鏃ユ湡鏍煎紡鍖栵紝鐗瑰埆鏄�"缂�  鍒�  鏃�  鏈�:"杩欎竴琛�
                         if (i == 5 && fieldValue instanceof Date) {
                             // 璁剧疆鏃ユ湡鏍煎紡涓簓yyy-MM-dd
@@ -391,6 +425,21 @@
                             cel.setCellValue(dateStr);
                         } else {
                             cel.setCellValue(fieldValue.toString());
+                        }
+
+                        // 瀵逛簬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);
+                            }
                         }
                       //  sheet.setColumnWidth(0, 60 * 256);
                         i++;
@@ -400,7 +449,7 @@
                             // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
                             row.setHeight((short) -1);
                             // row.setHeight((short) 30);
-                            row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+                            row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
                             row = sheet.createRow(9);
                             //璁剧疆鏉″舰鐮�
                             // 璁剧疆鏉″舰鐮�
@@ -409,23 +458,23 @@
                                 // 鍒涘缓鍗曞厓鏍�
                                 Cell barcodeCell = sheet.createRow(9).createCell(0);
                                 // 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず鏉″舰鐮�
-                                sheet.getRow(9).setHeightInPoints(70);
+                                sheet.getRow(9).setHeightInPoints(40);
                                 // 璁剧疆鍒楀瓒冲瀹戒互鏄剧ず鏉″舰鐮侊紝鍏堜繚瀛樺綋鍓嶅垪瀹�
                                 int currentColumnWidth0 = sheet.getColumnWidth(0);
                                 sheet.setColumnWidth(0, 40 * 256);
-                                
+
                                 // 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�10琛岀1鍒�
                                 // 鏉″舰鐮佸眳涓笖涓嶈秴鍑虹浜屼釜鏍煎瓙
                                 // 璋冩暣缁撴潫鍒楃储寮曞拰浣嶇疆鍙傛暟
                                 // 澧炲姞dx1鍊硷紝浣挎潯褰㈢爜鏁翠綋鍚戝彸绉诲姩
-                                ClientAnchor anchor1 = new HSSFClientAnchor(300, 50, 900, 200, (short) 0, 9, (short) 1, 10);
+                                ClientAnchor anchor1 = new HSSFClientAnchor(660, 50, 900, 200, (short) 0, 9, (short) 1, 10);
                                 // 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏�
                                 anchor1.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);
-                                
+
                                 // 娣诲姞鍥剧墖鍒板伐浣滆〃
                                 getDrawingPatriarch(sheet).createPicture(anchor1,
                                         wb.addPicture(dat, getImageType(dat)));
-                                
+
                                 // 鏉″舰鐮佹坊鍔犲畬鎴愬悗锛屾仮澶嶅師鏉ョ殑鍒楀璁剧疆
                                 sheet.setColumnWidth(0, currentColumnWidth0);
                             }
@@ -611,7 +660,7 @@
         for (Object[] os : fields)
         {
             Excel excel = (Excel) os[1];
-            String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
+            String key = StringUtils.format("header_{}_{}_{}_{}_{}", excel.headerColor(), excel.headerBackgroundColor(), excel.headerFontName(), excel.headerFontBold(), excel.headerFontSize());
             if (!headerStyles.containsKey(key))
             {
                  style = wb.createCellStyle();
@@ -626,8 +675,8 @@
                     style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                 }*/
                 Font headerFont = wb.createFont();
-                headerFont.setFontName("Arial");
-                headerFont.setFontHeightInPoints((short) 10);
+                headerFont.setFontName(excel.headerFontName());
+                headerFont.setFontHeightInPoints((short) excel.headerFontSize()); // 浣跨敤Excel娉ㄨВ涓殑headerFontSize灞炴��
                 headerFont.setBold(excel.headerFontBold());
                 headerFont.setColor(excel.headerColor().index);
                 style.setFont(headerFont);
@@ -681,7 +730,7 @@
         cell.setCellValue(attr.name());
         setDataValidation(attr, row, column);
         // 鏍规嵁Excel娉ㄨВ鍔ㄦ�侀�夋嫨琛ㄥご鏍峰紡
-        String key = StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor());
+        String key = StringUtils.format("header_{}_{}_{}_{}_{}", attr.headerColor(), attr.headerBackgroundColor(), attr.headerFontName(), attr.headerFontBold(), attr.headerFontSize());
         cell.setCellStyle(styles.get(key));
         return cell;
     }
@@ -1124,4 +1173,27 @@
         }
         return val;
     }
+
+    /**
+     * 灏咥pache POI鐨刉orkbook杞崲涓篈spose.Cells鐨刉orkbook
+     *
+     * @param poiWorkbook Apache POI鐨刉orkbook瀵硅薄
+     * @return Aspose.Cells鐨刉orkbook瀵硅薄
+     * @throws IOException IO寮傚父
+     */
+
+
+
 }
+
+
+
+
+
+
+
+
+
+
+
+

--
Gitblit v1.9.1