From af47b774448bfa3ece4741664ce4d24128c8f629 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期一, 01 九月 2025 14:29:50 +0800
Subject: [PATCH] 新增了代码

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java |  229 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 207 insertions(+), 22 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 6f40bb2..2dc3859 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
@@ -22,7 +22,10 @@
 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.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -267,9 +270,9 @@
      * @return 缁撴灉
      * @throws IOException
      */
-    public void exportExcelManySheet(HttpServletResponse response, List<ExcelExp> list) throws IOException {
-        response.setContentType("application/vnd.ms-excel");
-        response.setCharacterEncoding("utf-8");
+    public void exportExcelManySheet(ByteOutputStream response, List<ExcelExp> list) throws IOException {
+//        response.setContentType("application/vnd.ms-excel");
+//        response.setCharacterEncoding("utf-8");
         try {
             createWorkbook();
             for (int index = 0; index <list.size(); index++) {
@@ -278,22 +281,185 @@
                 // 鍙栧嚭涓�鍏辨湁澶氬皯涓猻heet.
 //                    double sheetNo = Math.ceil(list.size() / sheetSize);
                 createSheetManySheet(index);
-                // 浜х敓涓�琛�
-                Row row = sheet.createRow(0);
-                int column = 0;
-                // 鍐欏叆鍚勪釜瀛楁鐨勫垪澶村悕绉�
-                for (Object[] os : fields) {
-                    Excel excel = (Excel) os[1];
-                    this.createCell(excel, row, column++);
+                // 浜х敓涓�琛�    if(index == 1) {
+                if(index==1)
+                {
+                    Row row = sheet.createRow(0);
+                    row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
+                    int column = 0;
+                    row = sheet.createRow(0);
+                    sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 1));
+                    row = sheet.createRow(2);
+                    row.setHeightInPoints(120); // 璁剧疆琛岄珮涓�20纾�
+
+                    //鎷垮埌鍥剧墖
+                    // 鍒涘缓鍗曞厓鏍煎苟娣诲姞鍥剧墖
+                    Cell cell = row.createCell(0);
+//sheet.setColumnWidth(0, 20 * 256); // 绗竴鍒楀搴�20瀛楃
+//sheet.setColumnWidth(1, 15 * 256); // 绗簩鍒楀搴�15瀛楃
+//sheet.setColumnWidth(2, 25 * 256); // 绗笁鍒楀搴�25瀛楃 // 璁剧疆绗竴鍒楀搴︿负20涓瓧绗�
+
+                    ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
+                            cell.getRow().getRowNum() + 1);
+                    // 璁$畻灞呬腑浣嶇疆
+//                    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.setRow1(2);
+                    anchor.setRow2(3);
+                    byte[] data = list.get(index).getSedcode();
+// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
+                    anchor.setDx1(2400000);
+                    anchor.setDy1(100);
+
+                    anchor.setDy2(-600000);
+                    // 鑾峰彇鍥剧墖鍘熷灏哄
+                    BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
+                    double widthInEMU = image.getWidth() * 9525 * 0.2;
+                    double heightInEMU = image.getHeight() * 9525;
+
+                    // 璁剧疆鍥剧墖鍘熷灏哄
+                    anchor.setDx2(-100000); // 鍘熷瀹藉害
+                 //   anchor.setDy2((int)heightInEMU); // 鍘熷楂樺害
+//anchor.setCol1(5); // 浠庣6鍒楀紑濮嬫樉绀�
+//anchor.setCol2(10); // 鍒扮11鍒楃粨鏉�
+
+                    //Files.readAllBytes(Paths.get(RuoYiConfig.getProfile() + "/upload/2025/08/14/30_20250814212128A031.jpg"));
+//
+//
+//                    System.out.println(data.length);
+                    getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
+                            cell.getSheet().getWorkbook().addPicture(data, getImageType(data)));
+
+
+
+                    String [] tits = {"妗�        鍙�:","妗f棣�(瀹�)鍙�:","缂�  寰�  鍙�: ","鍙�  鏂�  鍙�:",
+                            "妗�  鍗�  棰�  鍚�:","缂�  鍒�  鏃�  鏈�:","缂�  鍒�  鍗�  浣�:","淇�  绠�  鏈�  闄�:","瀵�     绾�:"};
+
+                    List tmp = list.get(index).getDataset();
+                    Object obj = tmp.get(0);
+                    Field[] declaredFields = this.clazz.getDeclaredFields();
+                    System.out.println(declaredFields.length);
+                    int i = 0;
+                    for (Field field : declaredFields) {
+                        // 璁剧疆瀛楁鐨勮闂潈闄愶紝浠ヤ究浜庤闂鏈夊瓧娈�
+                        field.setAccessible(true);
+
+                        // 鑾峰彇瀛楁鐨勫悕绉板拰鍊�
+                        String fieldName = field.getName();
+                    //    Object fieldValue = field.get(person);
+                         Class<?> clazz = obj.getClass();
+                         Field field1 =clazz.getDeclaredField(fieldName);
+                         field1.setAccessible(true);
+                         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);
+                       // row.setHeight((short) 30);
+                        row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+                       // row.createCell(0)
+                        cell = row.createCell(0);
+                        //璁剧疆cell鐨勫搴�
+                        sheet.setColumnWidth(0, 20 * 256);
+                        sheet.setColumnWidth(1, 60 * 256); // 绗簩鍒楀搴�15瀛楃
+
+                        CellStyle style = wb.createCellStyle();
+                        style.setAlignment(HorizontalAlignment.RIGHT);
+                        style.setVerticalAlignment(VerticalAlignment.CENTER);
+style.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
+                      //  style.setAlignment(VerticalAlignment.CENTER);
+                        Font font = wb.createFont();
+                        font.setBold(true);
+                        style.setFont(font);
+style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+                        cell.setCellStyle(style);
+                        cell.setCellValue(tits[i]);
+                        Cell cel = row.createCell(1);
+                        CellStyle style1 = wb.createCellStyle();
+                        style1.setBorderBottom(BorderStyle.THIN); // 娣诲姞涓嬪垝绾�
+                        style1.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+                        style1.setVerticalAlignment(VerticalAlignment.CENTER);
+                        cel.setCellStyle(style1);
+                        cel.setCellValue(fieldValue.toString());
+                      //  sheet.setColumnWidth(0, 60 * 256);
+                        i++;
+                        if(i==3)
+                        {
+                            row = sheet.createRow(8);
+                            // row.setHeight((short) 30);
+                            row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+                            row = sheet.createRow(9);
+                            //璁剧疆鏉″舰鐮�
+                            Cell cell1 = row.createCell(0);
+//sheet.setColumnWidth(0, 20 * 256); // 绗竴鍒楀搴�20瀛楃
+//sheet.setColumnWidth(1, 15 * 256); // 绗簩鍒楀搴�15瀛楃
+//sheet.setColumnWidth(2, 25 * 256); // 绗笁鍒楀搴�25瀛楃 // 璁剧疆绗竴鍒楀搴︿负20涓瓧绗�
+
+                            ClientAnchor anchor1 = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell1.getColumnIndex()), cell1.getRow().getRowNum(), (short) (cell1.getColumnIndex() +2),
+                                    cell1.getRow().getRowNum() + 1);
+                            // 璁$畻灞呬腑浣嶇疆
+//// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
+anchor1.setDx1(600000);
+anchor1.setDy1(0);
+anchor1.setDx2(-600000); // 瀹藉害
+anchor1.setDy2(255); // 楂樺害
+//anchor1.setCol1(0.5); // 浠庣6鍒楀紑濮嬫樉绀�
+//anchor1.setCol2(10); // 鍒扮11鍒楃粨鏉�
+                            anchor1.setRow1(9);
+                            anchor1.setRow2(10);
+                            byte[] dat = list.get(index).getImgr();
+                            //Files.readAllBytes(Paths.get(RuoYiConfig.getProfile() + "/upload/2025/08/14/30_20250814212128A031.jpg"));
+//
+//
+//                    System.out.println(data.length);
+                            getDrawingPatriarch(cell1.getSheet()).createPicture(anchor1,
+                                    cell.getSheet().getWorkbook().addPicture(dat, getImageType(dat)));
+
+
+
+
+                            row.setHeightInPoints(70); // 璁剧疆琛岄珮涓�20纾�
+                            row = sheet.createRow(10);
+                            row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+                        }
+                        // 鎵撳嵃瀛楁鍚嶇О鍜屽��
+                        System.out.println(fieldName + ": " + fieldValue);
+                    }
+
+
+
+
                 }
-                if (Excel.Type.EXPORT.equals(type)) {
-                    fillExcelData(index, row);
-                    addStatisticsRow();
+                else {
+
+                    Row row = sheet.createRow(0);
+                    int column = 0;
+                    // 鍐欏叆鍚勪釜瀛楁鐨勫垪澶村悕绉�
+                    for (Object[] os : fields) {
+                        Excel excel = (Excel) os[1];
+                        this.createCell(excel, row, column++);
+                    }
+                    if (Excel.Type.EXPORT.equals(type)) {
+                        fillExcelData(index, row);
+                        addStatisticsRow();
+                    }
                 }
             }
-            wb.write(response.getOutputStream());
+            wb.write(response);
         } catch (IOException e) {
             log.error("瀵煎嚭Excel寮傚父{}", e.getMessage());
+        } catch (NoSuchFieldException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
         } finally {
             if (wb != null) {
                 try {
@@ -302,13 +468,13 @@
                     e1.printStackTrace();
                 }
             }
-            if (response.getOutputStream() != null) {
-                try {
-                    response.getOutputStream().close();
-                } catch (IOException e1) {
-                    e1.printStackTrace();
-                }
-            }
+//            if (response.getOutputStream() != null) {
+//                try {
+//                    response.getOutputStream().close();
+//                } catch (IOException e1) {
+//                    e1.printStackTrace();
+//                }
+//            }
         }
 //        exportExcel(response.getOutputStream());
     }
@@ -388,6 +554,10 @@
                 row = sheet.createRow(i + 4 );
             else
                 row = sheet.createRow(i + 1 );
+
+            row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+            // row.createCell(0)
+
             // 寰楀埌瀵煎嚭瀵硅薄.
             T vo = (T) list.get(i);
             int column = 0;
@@ -557,11 +727,26 @@
         Cell cell = null;
         try {
             // 璁剧疆琛岄珮
-            row.setHeight(maxHeight);
+            row.setHeight((short) 2000);
             // 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
             if (attr.isExport()) {
                 // 鍒涘缓cell
                 cell = row.createCell(column);
+                //璁剧疆cell鐨勫搴�
+                sheet.setColumnWidth(0, 20 * 256);
+                sheet.setColumnWidth(1, 60 * 256); // 绗簩鍒楀搴�15瀛楃
+
+                CellStyle style = wb.createCellStyle();
+//                style.setAlignment(HorizontalAlignment.RIGHT);
+                style.setVerticalAlignment(VerticalAlignment.CENTER);
+                style.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
+                //  style.setAlignment(VerticalAlignment.CENTER);
+                Font font = wb.createFont();
+                font.setBold(true);
+                style.setFont(font);
+                style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+
+                cell.setCellStyle(style);
 //                attr.align();
 //                int align = attr.align().value;
 //                cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));

--
Gitblit v1.9.1