Excel.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 color() default IndexedColors.BLACK;
  95. /**
  96. * 导出字段对齐方式
  97. */
  98. public HorizontalAlignment align() default HorizontalAlignment.CENTER;
  99. /**
  100. * 自定义数据处理器
  101. */
  102. public Class<?> handler() default ExcelHandlerAdapter.class;
  103. /**
  104. * 自定义数据处理器参数
  105. */
  106. public String[] args() default {};
  107. public enum Align
  108. {
  109. AUTO(0), LEFT(1), CENTER(2), RIGHT(3);
  110. private final int value;
  111. Align(int value)
  112. {
  113. this.value = value;
  114. }
  115. public int value()
  116. {
  117. return this.value;
  118. }
  119. }
  120. /**
  121. * 字段类型(0:导出导入;1:仅导出;2:仅导入)
  122. */
  123. Type type() default Type.ALL;
  124. public enum Type
  125. {
  126. ALL(0), EXPORT(1), IMPORT(2);
  127. private final int value;
  128. Type(int value)
  129. {
  130. this.value = value;
  131. }
  132. public int value()
  133. {
  134. return this.value;
  135. }
  136. }
  137. public enum ColumnType
  138. {
  139. NUMERIC(0), STRING(1), IMAGE(2);
  140. private final int value;
  141. ColumnType(int value)
  142. {
  143. this.value = value;
  144. }
  145. public int value()
  146. {
  147. return this.value;
  148. }
  149. }
  150. }