Excel.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. * 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
  77. */
  78. public boolean isExport() default true;
  79. /**
  80. * 另一个类中的属性名称,支持多级获取,以小数点隔开
  81. */
  82. public String targetAttr() default "";
  83. /**
  84. * 是否自动统计数据,在最后追加一行统计数据总和
  85. */
  86. public boolean isStatistics() default false;
  87. /**
  88. * 导出类型(0数字 1字符串)
  89. */
  90. public ColumnType cellType() default ColumnType.STRING;
  91. /**
  92. * 导出列头背景色
  93. */
  94. public IndexedColors headerBackgroundColor() default IndexedColors.GREY_50_PERCENT;
  95. /**
  96. * 导出列头字体颜色
  97. */
  98. public IndexedColors headerColor() default IndexedColors.WHITE;
  99. /**
  100. * 导出单元格背景色
  101. */
  102. public IndexedColors backgroundColor() default IndexedColors.WHITE;
  103. /**
  104. * 导出单元格字体颜色
  105. */
  106. public IndexedColors color() default IndexedColors.BLACK;
  107. /**
  108. * 导出字段对齐方式
  109. */
  110. public HorizontalAlignment align() default HorizontalAlignment.CENTER;
  111. /**
  112. * 自定义数据处理器
  113. */
  114. public Class<?> handler() default ExcelHandlerAdapter.class;
  115. /**
  116. * 自定义数据处理器参数
  117. */
  118. public String[] args() default {};
  119. public enum Align
  120. {
  121. AUTO(0), LEFT(1), CENTER(2), RIGHT(3);
  122. private final int value;
  123. Align(int value)
  124. {
  125. this.value = value;
  126. }
  127. public int value()
  128. {
  129. return this.value;
  130. }
  131. }
  132. /**
  133. * 字段类型(0:导出导入;1:仅导出;2:仅导入)
  134. */
  135. Type type() default Type.ALL;
  136. public enum Type
  137. {
  138. ALL(0), EXPORT(1), IMPORT(2);
  139. private final int value;
  140. Type(int value)
  141. {
  142. this.value = value;
  143. }
  144. public int value()
  145. {
  146. return this.value;
  147. }
  148. }
  149. public enum ColumnType
  150. {
  151. NUMERIC(0), STRING(1), IMAGE(2);
  152. private final int value;
  153. ColumnType(int value)
  154. {
  155. this.value = value;
  156. }
  157. public int value()
  158. {
  159. return this.value;
  160. }
  161. }
  162. }