Browse Source

整改清单导出调整参数

zhuang 11 months ago
parent
commit
f1ff1cebe9

+ 32 - 10
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxProjectManageServiceImpl.java

@@ -464,22 +464,40 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
         }
 
         WorksheetCollection worksheets = workbook.getWorksheets();
-        worksheets.add("整改统计");
-        Worksheet worksheet = worksheets.get(1);
+
+        Workbook workbook1 = new Workbook();
+        WorksheetCollection worksheets1 = workbook1.getWorksheets();
+
+        worksheets1.add("整改统计");
+        Worksheet worksheet = worksheets1.get(1);
 
         Map<String, Object> map = new HashMap<>();
         map.put("projectId", dto.getProjectId());
         map.put("projname", dto.getFileName());
 
         //导出
-        int result = exportRectifyReportDataBySheet(workbook, worksheet, map);
+        int result = exportRectifyReportDataBySheet(workbook1, worksheet, map);
         try {
+            // 记录第一列的原始宽度
+            double firstColumnWidth = worksheet.getCells().getColumnWidth(0);
+            // 调整所有列的宽度
+            worksheet.autoFitColumns();
+            // 恢复第一列的宽度
+            worksheet.getCells().setColumnWidth(0, firstColumnWidth);
+            Worksheet sourceWorksheet = worksheets.get(0);
+            Worksheet targetWorksheet = worksheets1.get(0);
+            try {
+                targetWorksheet.copy(sourceWorksheet);
+                targetWorksheet.setName("整改清单");
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
             response.addHeader("Pargam", "no-cache");
             response.addHeader("Cache-Control", "no-cache");
             response.setContentType("application/octet-stream;charset=ISO8859-1");
             response.setHeader("Content-Disposition", "attachment;filename=整改清单.xlsx");
-            workbook.save(response.getOutputStream(), SaveFormat.XLSX);
-            workbook.dispose();
+            workbook1.save(response.getOutputStream(), SaveFormat.XLSX);
+            workbook1.dispose();
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -731,16 +749,20 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
             int pictureHeight = picture.getHeight();
 
             // 计算图片在单元格中的偏移量
-            int offsetX = (int) ((cellWidth - pictureWidth));
+            int offsetX = (int) ((cellWidth - pictureWidth)/2);
             int offsetY = (int) ((cellHeight - pictureHeight));
 
             // 确保图片在单元格内居中
-            picture.setLeft(offsetX);
-            picture.setTop(offsetY);
+            //picture.setLeft(offsetX);
+            //picture.setTop(offsetY);
 
             // 将单元格宽度和高度调整为适合图片的大小
-            worksheet.getCells().setColumnWidthPixel(0, Math.max(pictureWidth, (int) cellWidth));
-            worksheet.getCells().setRowHeightPixel(0, Math.max(pictureHeight, (int) cellHeight));
+            //worksheet.getCells().setColumnWidthPixel(0, Math.max(pictureWidth, (int) cellWidth));
+            //worksheet.getCells().setRowHeightPixel(0, Math.max(pictureHeight, (int) cellHeight));
+            picture.setLeft(offsetX - 5);
+            picture.setTop(offsetY);
+            worksheet.getCells().setColumnWidthPixel(0, pictureWidth);
+            worksheet.getCells().setRowHeightPixel(0, pictureHeight);
         } catch (Exception e) {
             log.error("整改清单导出报错", e);
         }