Przeglądaj źródła

Excel注解支持wrapText是否允许内容换行

RuoYi 1 rok temu
rodzic
commit
6c3b01c3c5

+ 5 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java

@@ -79,6 +79,11 @@ public @interface Excel
79
     public String prompt() default "";
79
     public String prompt() default "";
80
 
80
 
81
     /**
81
     /**
82
+     * 是否允许内容换行 
83
+     */
84
+    public boolean wrapText() default false;
85
+
86
+    /**
82
      * 设置只能选择不能输入的列内容.
87
      * 设置只能选择不能输入的列内容.
83
      */
88
      */
84
     public String[] combo() default {};
89
     public String[] combo() default {};

+ 4 - 3
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java

@@ -814,7 +814,7 @@ public class ExcelUtil<T>
814
      */
814
      */
815
     public void annotationDataStyles(Map<String, CellStyle> styles, Field field, Excel excel)
815
     public void annotationDataStyles(Map<String, CellStyle> styles, Field field, Excel excel)
816
     {
816
     {
817
-        String key = StringUtils.format("data_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType());
817
+        String key = StringUtils.format("data_{}_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType(), excel.wrapText());
818
         if (!styles.containsKey(key))
818
         if (!styles.containsKey(key))
819
         {
819
         {
820
             CellStyle style = wb.createCellStyle();
820
             CellStyle style = wb.createCellStyle();
@@ -830,6 +830,7 @@ public class ExcelUtil<T>
830
             style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
830
             style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
831
             style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
831
             style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
832
             style.setFillForegroundColor(excel.backgroundColor().getIndex());
832
             style.setFillForegroundColor(excel.backgroundColor().getIndex());
833
+            style.setWrapText(excel.wrapText());
833
             Font dataFont = wb.createFont();
834
             Font dataFont = wb.createFont();
834
             dataFont.setFontName("Arial");
835
             dataFont.setFontName("Arial");
835
             dataFont.setFontHeightInPoints((short) 10);
836
             dataFont.setFontHeightInPoints((short) 10);
@@ -858,7 +859,7 @@ public class ExcelUtil<T>
858
         if (isSubList())
859
         if (isSubList())
859
         {
860
         {
860
             // 填充默认样式,防止合并单元格样式失效
861
             // 填充默认样式,防止合并单元格样式失效
861
-            sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType())));
862
+            sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
862
             if (attr.needMerge())
863
             if (attr.needMerge())
863
             {
864
             {
864
                 sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
865
                 sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
@@ -990,7 +991,7 @@ public class ExcelUtil<T>
990
                         sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column));
991
                         sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column));
991
                     }
992
                     }
992
                 }
993
                 }
993
-                cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType())));
994
+                cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
994
 
995
 
995
                 // 用于读取对象中的属性
996
                 // 用于读取对象中的属性
996
                 Object value = getTargetValue(vo, field, attr);
997
                 Object value = getTargetValue(vo, field, attr);