Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CellCopyPolicy.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package org.apache.poi.ss.usermodel;
  2. import org.apache.poi.util.Beta;
  3. @Beta
  4. public class CellCopyPolicy implements Cloneable {
  5. public static final boolean DEFAULT_COPY_CELL_VALUE_POLICY = true;
  6. public static final boolean DEFAULT_COPY_CELL_STYLE_POLICY = true;
  7. public static final boolean DEFAULT_COPY_CELL_FORMULA_POLICY = true;
  8. public static final boolean DEFAULT_COPY_MERGED_REGIONS_POLICY = true;
  9. public static final boolean DEFAULT_COPY_ROW_HEIGHT_POLICY = true;
  10. public static final boolean DEFAULT_CONDENSE_ROWS_POLICY = false;
  11. private boolean copyCellValue = DEFAULT_COPY_CELL_VALUE_POLICY;
  12. private boolean copyCellStyle = DEFAULT_COPY_CELL_STYLE_POLICY;
  13. private boolean copyCellFormula = DEFAULT_COPY_CELL_FORMULA_POLICY;
  14. private boolean copyMergedRegions = DEFAULT_COPY_MERGED_REGIONS_POLICY;
  15. private boolean copyRowHeight = DEFAULT_COPY_ROW_HEIGHT_POLICY;
  16. private boolean condenseRows = DEFAULT_CONDENSE_ROWS_POLICY;
  17. /**
  18. * Default CellCopyPolicy, uses default policy
  19. * For custom CellCopyPolicy, use {@link #Builder} class
  20. */
  21. public CellCopyPolicy() { }
  22. // should builder be replaced with CellCopyPolicy setters that return the object
  23. // to allow setters to be chained together?
  24. // policy.setCopyCellValue(true).setCopyCellStyle(true)
  25. private CellCopyPolicy(Builder builder) {
  26. copyCellValue = builder.copyCellValue;
  27. copyCellStyle = builder.copyCellStyle;
  28. copyCellFormula = builder.copyCellFormula;
  29. copyMergedRegions = builder.copyMergedRegions;
  30. copyRowHeight = builder.copyRowHeight;
  31. condenseRows = builder.condenseRows;
  32. }
  33. public static class Builder {
  34. private boolean copyCellValue = DEFAULT_COPY_CELL_VALUE_POLICY;
  35. private boolean copyCellStyle = DEFAULT_COPY_CELL_STYLE_POLICY;
  36. private boolean copyCellFormula = DEFAULT_COPY_CELL_FORMULA_POLICY;
  37. private boolean copyMergedRegions = DEFAULT_COPY_MERGED_REGIONS_POLICY;
  38. private boolean copyRowHeight = DEFAULT_COPY_ROW_HEIGHT_POLICY;
  39. private boolean condenseRows = DEFAULT_CONDENSE_ROWS_POLICY;
  40. /**
  41. * Builder class for CellCopyPolicy
  42. */
  43. public Builder() {
  44. }
  45. public Builder cellValue(boolean copyCellValue) {
  46. this.copyCellValue = copyCellValue;
  47. return this;
  48. }
  49. public Builder cellStyle(boolean copyCellStyle) {
  50. this.copyCellStyle = copyCellStyle;
  51. return this;
  52. }
  53. public Builder cellFormula(boolean copyCellFormula) {
  54. this.copyCellFormula = copyCellFormula;
  55. return this;
  56. }
  57. public Builder mergedRegions(boolean copyMergedRegions) {
  58. this.copyMergedRegions = copyMergedRegions;
  59. return this;
  60. }
  61. public Builder rowHeight(boolean copyRowHeight) {
  62. this.copyRowHeight = copyRowHeight;
  63. return this;
  64. }
  65. public Builder condenseRows(boolean condenseRows) {
  66. this.condenseRows = condenseRows;
  67. return this;
  68. }
  69. public CellCopyPolicy build() {
  70. return new CellCopyPolicy(this);
  71. }
  72. }
  73. private Builder createBuilder() {
  74. final Builder builder = new Builder()
  75. .cellValue(copyCellValue)
  76. .cellStyle(copyCellStyle)
  77. .cellFormula(copyCellFormula)
  78. .mergedRegions(copyMergedRegions)
  79. .rowHeight(copyRowHeight)
  80. .condenseRows(condenseRows);
  81. return builder;
  82. }
  83. @Override
  84. public CellCopyPolicy clone() {
  85. return createBuilder().build();
  86. }
  87. /**
  88. * @return the copyCellValue
  89. */
  90. public boolean isCopyCellValue() {
  91. return copyCellValue;
  92. }
  93. /**
  94. * @param copyCellValue the copyCellValue to set
  95. */
  96. public void setCopyCellValue(boolean copyCellValue) {
  97. this.copyCellValue = copyCellValue;
  98. }
  99. /**
  100. * @return the copyCellStyle
  101. */
  102. public boolean isCopyCellStyle() {
  103. return copyCellStyle;
  104. }
  105. /**
  106. * @param copyCellStyle the copyCellStyle to set
  107. */
  108. public void setCopyCellStyle(boolean copyCellStyle) {
  109. this.copyCellStyle = copyCellStyle;
  110. }
  111. /**
  112. * @return the copyCellFormula
  113. */
  114. public boolean isCopyCellFormula() {
  115. return copyCellFormula;
  116. }
  117. /**
  118. * @param copyCellFormula the copyCellFormula to set
  119. */
  120. public void setCopyCellFormula(boolean copyCellFormula) {
  121. this.copyCellFormula = copyCellFormula;
  122. }
  123. /**
  124. * @return the copyMergedRegions
  125. */
  126. public boolean isCopyMergedRegions() {
  127. return copyMergedRegions;
  128. }
  129. /**
  130. * @param copyMergedRegions the copyMergedRegions to set
  131. */
  132. public void setCopyMergedRegions(boolean copyMergedRegions) {
  133. this.copyMergedRegions = copyMergedRegions;
  134. }
  135. /**
  136. * @return the copyRowHeight
  137. */
  138. public boolean isCopyRowHeight() {
  139. return copyRowHeight;
  140. }
  141. /**
  142. * @param copyRowHeight the copyRowHeight to set
  143. */
  144. public void setCopyRowHeight(boolean copyRowHeight) {
  145. this.copyRowHeight = copyRowHeight;
  146. }
  147. /**
  148. * If condenseRows is true, a discontinuities in srcRows will be removed when copied to destination
  149. * For example:
  150. * Sheet.copyRows({Row(1), Row(2), Row(5)}, 11, policy) results in rows 1, 2, and 5
  151. * being copied to rows 11, 12, and 13 if condenseRows is True, or rows 11, 11, 15 if condenseRows is false
  152. * @return the condenseRows
  153. */
  154. public boolean isCondenseRows() {
  155. return condenseRows;
  156. }
  157. /**
  158. * @param condenseRows the condenseRows to set
  159. */
  160. public void setCondenseRows(boolean condenseRows) {
  161. this.condenseRows = condenseRows;
  162. }
  163. }