TableColumn.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * 文件名:TableColumn.java
  3. * 版权:
  4. * 描述:
  5. * 修改人:
  6. * 修改时间:
  7. * 修改内容:
  8. */
  9. package com.post.excelTools;
  10. import java.util.LinkedList;
  11. import java.util.List;
  12. public class TableColumn {
  13. /**
  14. * 字符串型
  15. */
  16. public static final int COLUMN_TYPE_STRING = 0;
  17. /**
  18. * 浮点型,保留2位小数
  19. */
  20. public static final int COLUMN_TYPE_FLOAT_2 = 1;
  21. /**
  22. * 浮点型,保留3位小数
  23. */
  24. public static final int COLUMN_TYPE_FLOAT_3 = 2;
  25. /**
  26. * 整形
  27. */
  28. public static final int COLUMN_TYPE_INTEGER = 3;
  29. /**
  30. * 公式字段
  31. */
  32. public static final int COLUMN_TYPE_FORMULA = 4;
  33. /**
  34. * 红色背景
  35. */
  36. public static final int COLUMN_TYPE_RED_BG = 10;
  37. /**
  38. * 黄色背景
  39. */
  40. public static final int COLUMN_TYPE_YELLOW_BG = 11;
  41. /**
  42. * 绿色背景
  43. */
  44. public static final int COLUMN_TYPE_GREEN_BG = 12;
  45. /**
  46. * 列id
  47. */
  48. private String id;
  49. /**
  50. * 列显示字符
  51. */
  52. private String display;
  53. /**
  54. * 列对应数据库字段
  55. */
  56. private String dbField;
  57. /**
  58. * 列数据类型,参考静态变量COLUMN_TYPE_* 默认为{@link #COLUMN_TYPE_STRING}
  59. */
  60. private int columnType = COLUMN_TYPE_STRING;
  61. /**
  62. * 是否合并相同行, 默认false
  63. */
  64. private boolean grouped = false;
  65. /**
  66. * 是否显示小计,只在该列为grouped情况下生效, 默认false
  67. */
  68. private boolean displaySummary = false;
  69. /**
  70. * 小计的聚集方法,包括:sum、avg、max
  71. */
  72. private String aggregateRule;
  73. /**
  74. * 是否显示该列, 默认true
  75. */
  76. private boolean isVisible = true;
  77. /**
  78. * 标识该列是否为复合表头, 默认false
  79. */
  80. private boolean isComplex = false;
  81. /**
  82. * 列描述
  83. */
  84. private String common;
  85. /**
  86. * 列宽度,主要用于前台显示,默认100长度单位
  87. */
  88. private int width = 100;
  89. /**
  90. * 列宽度(百分比形式),主要用于前台显示
  91. */
  92. private int percentWidth;
  93. /**
  94. * 列的宽度类型,分为百分比宽度和实际宽度,分别以 P 和 A 表示,默认为P
  95. */
  96. private String widthType = "P";
  97. protected int level;
  98. protected TableColumn parent = null;
  99. /**
  100. * 复合表头,拥有子列
  101. */
  102. protected List<TableColumn> children = new LinkedList<TableColumn>();
  103. public void addChild(TableColumn column) {
  104. children.add(column);
  105. column.parent = this;
  106. if (column.isVisible())
  107. isComplex = true;
  108. }
  109. public List<TableColumn> getChildren() {
  110. LinkedList<TableColumn> ret = new LinkedList<TableColumn>();
  111. for (TableColumn c : children) {
  112. if (c.isVisible())
  113. ret.add(c);
  114. }
  115. return ret;
  116. }
  117. public boolean isComplex() {
  118. return isComplex;
  119. }
  120. public int getLength() {
  121. int len = 0;
  122. if (isComplex()) {
  123. for (TableColumn col : getChildren()) {
  124. len += col.getLength();
  125. }
  126. } else {
  127. len = 1;
  128. }
  129. return len;
  130. }
  131. public String getDisplay() {
  132. return display;
  133. }
  134. public void setDisplay(String display) {
  135. this.display = display;
  136. }
  137. public String getDbField() {
  138. return dbField;
  139. }
  140. public void setDbField(String dbField) {
  141. this.dbField = dbField;
  142. }
  143. public int getColumnType() {
  144. return columnType;
  145. }
  146. public String getColumnStringType(int columnType) {
  147. String stringType = "string";
  148. if (columnType == this.COLUMN_TYPE_INTEGER) {
  149. stringType = "int";
  150. } else if (columnType == this.COLUMN_TYPE_FLOAT_2) {
  151. stringType = "float";
  152. } else if (columnType == this.COLUMN_TYPE_FLOAT_3) {
  153. stringType = "float";
  154. }
  155. return stringType;
  156. }
  157. public void setColumnType(int columnType) {
  158. this.columnType = columnType;
  159. }
  160. public boolean isGrouped() {
  161. return grouped;
  162. }
  163. public void setGrouped(boolean grouped) {
  164. this.grouped = grouped;
  165. }
  166. public boolean isDisplaySummary() {
  167. return displaySummary;
  168. }
  169. public void setDisplaySummary(boolean displaySummary) {
  170. this.displaySummary = displaySummary;
  171. }
  172. public boolean isVisible() {
  173. return isVisible;
  174. }
  175. public void setVisible(boolean isVisible) {
  176. this.isVisible = isVisible;
  177. }
  178. public String getAggregateRule() {
  179. return aggregateRule;
  180. }
  181. public void setAggregateRule(String aggregateRule) {
  182. this.aggregateRule = aggregateRule;
  183. }
  184. public String getId() {
  185. return id;
  186. }
  187. public void setId(String id) {
  188. this.id = id;
  189. }
  190. public String getCommon() {
  191. return common;
  192. }
  193. public void setCommon(String common) {
  194. this.common = common;
  195. }
  196. public int getWidth() {
  197. return width;
  198. }
  199. public void setWidth(int width) {
  200. this.width = width;
  201. }
  202. public int getPercentWidth() {
  203. return percentWidth;
  204. }
  205. public void setPercentWidth(int percentWidth) {
  206. this.percentWidth = percentWidth;
  207. }
  208. public String getWidthType() {
  209. return widthType;
  210. }
  211. public void setWidthType(String widthType) {
  212. this.widthType = widthType;
  213. }
  214. }