Excel.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package com.ruoyi.common.annotation;
  2. import java.lang.annotation.ElementType;
  3. import java.lang.annotation.Retention;
  4. import java.lang.annotation.RetentionPolicy;
  5. import java.lang.annotation.Target;
  6. import java.math.BigDecimal;
  7. import org.apache.poi.ss.usermodel.HorizontalAlignment;
  8. import org.apache.poi.ss.usermodel.IndexedColors;
  9. import com.ruoyi.common.utils.poi.ExcelHandlerAdapter;
  10. /**
  11. * 自定义导出Excel数据注解
  12. *
  13. * @author ruoyi
  14. */
  15. @Retention(RetentionPolicy.RUNTIME)
  16. @Target(ElementType.FIELD)
  17. public @interface Excel
  18. {
  19. /**
  20. * 导出时在excel中排序
  21. */
  22. public int sort() default Integer.MAX_VALUE;
  23. /**
  24. * 导出到Excel中的名字.
  25. */
  26. public String name() default "";
  27. /**
  28. * 日期格式, 如: yyyy-MM-dd
  29. */
  30. public String dateFormat() default "";
  31. /**
  32. * 如果是字典类型,请设置字典的type值 (如: sys_user_sex)
  33. */
  34. public String dictType() default "";
  35. /**
  36. * 读取内容转表达式 (如: 0=男,1=女,2=未知)
  37. */
  38. public String readConverterExp() default "";
  39. /**
  40. * 分隔符,读取字符串组内容
  41. */
  42. public String separator() default ",";
  43. /**
  44. * BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
  45. */
  46. public int scale() default -1;
  47. /**
  48. * BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
  49. */
  50. public int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
  51. /**
  52. * 导出时在excel中每个列的高度
  53. */
  54. public double height() default 14;
  55. /**
  56. * 导出时在excel中每个列的宽度
  57. */
  58. public double width() default 16;
  59. /**
  60. * 文字后缀,如% 90 变成90%
  61. */
  62. public String suffix() default "";
  63. /**
  64. * 当值为空时,字段的默认值
  65. */
  66. public String defaultValue() default "";
  67. /**
  68. * 提示信息
  69. */
  70. public String prompt() default "";
  71. /**
  72. * 设置只能选择不能输入的列内容.
  73. */
  74. public String[] combo() default {};
  75. /**
  76. * 是否需要纵向合并单元格,应对需求:含有list集合单元格)
  77. */
  78. public boolean needMerge() default false;
  79. /**
  80. * 是否需要自动换行
  81. */
  82. public boolean warpText() default false;
  83. /**
  84. * 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
  85. */
  86. public boolean isExport() default true;
  87. /**
  88. * 另一个类中的属性名称,支持多级获取,以小数点隔开
  89. */
  90. public String targetAttr() default "";
  91. /**
  92. * 是否自动统计数据,在最后追加一行统计数据总和
  93. */
  94. public boolean isStatistics() default false;
  95. /**
  96. * 导出类型(0数字 1字符串 2图片)
  97. */
  98. public ColumnType cellType() default ColumnType.STRING;
  99. /**
  100. * 导出列头背景颜色
  101. */
  102. public IndexedColors headerBackgroundColor() default IndexedColors.GREY_50_PERCENT;
  103. /**
  104. * 导出列头字体颜色
  105. */
  106. public IndexedColors headerColor() default IndexedColors.WHITE;
  107. /**
  108. * 导出单元格背景颜色
  109. */
  110. public IndexedColors backgroundColor() default IndexedColors.WHITE;
  111. /**
  112. * 导出单元格字体颜色
  113. */
  114. public IndexedColors color() default IndexedColors.BLACK;
  115. /**
  116. * 导出字段对齐方式
  117. */
  118. public HorizontalAlignment align() default HorizontalAlignment.CENTER;
  119. /**
  120. * 自定义数据处理器
  121. */
  122. public Class<?> handler() default ExcelHandlerAdapter.class;
  123. /**
  124. * 自定义数据处理器参数
  125. */
  126. public String[] args() default {};
  127. /**
  128. * 字段类型(0:导出导入;1:仅导出;2:仅导入)
  129. */
  130. Type type() default Type.ALL;
  131. public enum Type
  132. {
  133. ALL(0), EXPORT(1), IMPORT(2);
  134. private final int value;
  135. Type(int value)
  136. {
  137. this.value = value;
  138. }
  139. public int value()
  140. {
  141. return this.value;
  142. }
  143. }
  144. public enum ColumnType
  145. {
  146. NUMERIC(0), STRING(1), IMAGE(2);
  147. private final int value;
  148. ColumnType(int value)
  149. {
  150. this.value = value;
  151. }
  152. public int value()
  153. {
  154. return this.value;
  155. }
  156. }
  157. }