You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CellCopyPolicy.java 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.usermodel;
  16. import org.apache.poi.util.Beta;
  17. @Beta
  18. public class CellCopyPolicy {
  19. // cell-level policies
  20. public static final boolean DEFAULT_COPY_CELL_VALUE_POLICY = true;
  21. public static final boolean DEFAULT_COPY_CELL_STYLE_POLICY = true;
  22. public static final boolean DEFAULT_COPY_CELL_FORMULA_POLICY = true;
  23. public static final boolean DEFAULT_COPY_HYPERLINK_POLICY = true;
  24. public static final boolean DEFAULT_MERGE_HYPERLINK_POLICY = false;
  25. // row-level policies
  26. public static final boolean DEFAULT_COPY_ROW_HEIGHT_POLICY = true;
  27. public static final boolean DEFAULT_CONDENSE_ROWS_POLICY = false;
  28. // sheet-level policies
  29. public static final boolean DEFAULT_COPY_MERGED_REGIONS_POLICY = true;
  30. // cell-level policies
  31. private boolean copyCellValue = DEFAULT_COPY_CELL_VALUE_POLICY;
  32. private boolean copyCellStyle = DEFAULT_COPY_CELL_STYLE_POLICY;
  33. private boolean copyCellFormula = DEFAULT_COPY_CELL_FORMULA_POLICY;
  34. private boolean copyHyperlink = DEFAULT_COPY_HYPERLINK_POLICY;
  35. private boolean mergeHyperlink = DEFAULT_MERGE_HYPERLINK_POLICY;
  36. // row-level policies
  37. private boolean copyRowHeight = DEFAULT_COPY_ROW_HEIGHT_POLICY;
  38. private boolean condenseRows = DEFAULT_CONDENSE_ROWS_POLICY;
  39. // sheet-level policies
  40. private boolean copyMergedRegions = DEFAULT_COPY_MERGED_REGIONS_POLICY;
  41. /**
  42. * Default CellCopyPolicy, uses default policy
  43. * For custom CellCopyPolicy, use {@link Builder} class
  44. */
  45. public CellCopyPolicy() { }
  46. /**
  47. * Copy constructor
  48. *
  49. * @param other policy to copy
  50. */
  51. public CellCopyPolicy(CellCopyPolicy other) {
  52. copyCellValue = other.isCopyCellValue();
  53. copyCellStyle = other.isCopyCellStyle();
  54. copyCellFormula = other.isCopyCellFormula();
  55. copyHyperlink = other.isCopyHyperlink();
  56. mergeHyperlink = other.isMergeHyperlink();
  57. copyRowHeight = other.isCopyRowHeight();
  58. condenseRows = other.isCondenseRows();
  59. copyMergedRegions = other.isCopyMergedRegions();
  60. }
  61. // should builder be replaced with CellCopyPolicy setters that return the object
  62. // to allow setters to be chained together?
  63. // policy.setCopyCellValue(true).setCopyCellStyle(true)
  64. private CellCopyPolicy(Builder builder) {
  65. copyCellValue = builder.copyCellValue;
  66. copyCellStyle = builder.copyCellStyle;
  67. copyCellFormula = builder.copyCellFormula;
  68. copyHyperlink = builder.copyHyperlink;
  69. mergeHyperlink = builder.mergeHyperlink;
  70. copyRowHeight = builder.copyRowHeight;
  71. condenseRows = builder.condenseRows;
  72. copyMergedRegions = builder.copyMergedRegions;
  73. }
  74. public static class Builder {
  75. // cell-level policies
  76. private boolean copyCellValue = DEFAULT_COPY_CELL_VALUE_POLICY;
  77. private boolean copyCellStyle = DEFAULT_COPY_CELL_STYLE_POLICY;
  78. private boolean copyCellFormula = DEFAULT_COPY_CELL_FORMULA_POLICY;
  79. private boolean copyHyperlink = DEFAULT_COPY_HYPERLINK_POLICY;
  80. private boolean mergeHyperlink = DEFAULT_MERGE_HYPERLINK_POLICY;
  81. // row-level policies
  82. private boolean copyRowHeight = DEFAULT_COPY_ROW_HEIGHT_POLICY;
  83. private boolean condenseRows = DEFAULT_CONDENSE_ROWS_POLICY;
  84. // sheet-level policies
  85. private boolean copyMergedRegions = DEFAULT_COPY_MERGED_REGIONS_POLICY;
  86. /**
  87. * Builder class for CellCopyPolicy
  88. */
  89. public Builder() {
  90. }
  91. // cell-level policies
  92. public Builder cellValue(boolean copyCellValue) {
  93. this.copyCellValue = copyCellValue;
  94. return this;
  95. }
  96. public Builder cellStyle(boolean copyCellStyle) {
  97. this.copyCellStyle = copyCellStyle;
  98. return this;
  99. }
  100. public Builder cellFormula(boolean copyCellFormula) {
  101. this.copyCellFormula = copyCellFormula;
  102. return this;
  103. }
  104. public Builder copyHyperlink(boolean copyHyperlink) {
  105. this.copyHyperlink = copyHyperlink;
  106. return this;
  107. }
  108. public Builder mergeHyperlink(boolean mergeHyperlink) {
  109. this.mergeHyperlink = mergeHyperlink;
  110. return this;
  111. }
  112. // row-level policies
  113. public Builder rowHeight(boolean copyRowHeight) {
  114. this.copyRowHeight = copyRowHeight;
  115. return this;
  116. }
  117. public Builder condenseRows(boolean condenseRows) {
  118. this.condenseRows = condenseRows;
  119. return this;
  120. }
  121. // sheet-level policies
  122. public Builder mergedRegions(boolean copyMergedRegions) {
  123. this.copyMergedRegions = copyMergedRegions;
  124. return this;
  125. }
  126. public CellCopyPolicy build() {
  127. return new CellCopyPolicy(this);
  128. }
  129. }
  130. public Builder createBuilder() {
  131. return new Builder()
  132. .cellValue(copyCellValue)
  133. .cellStyle(copyCellStyle)
  134. .cellFormula(copyCellFormula)
  135. .copyHyperlink(copyHyperlink)
  136. .mergeHyperlink(mergeHyperlink)
  137. .rowHeight(copyRowHeight)
  138. .condenseRows(condenseRows)
  139. .mergedRegions(copyMergedRegions);
  140. }
  141. /*
  142. * Cell-level policies
  143. */
  144. /**
  145. * @return the copyCellValue
  146. */
  147. public boolean isCopyCellValue() {
  148. return copyCellValue;
  149. }
  150. /**
  151. * @param copyCellValue the copyCellValue to set
  152. */
  153. public void setCopyCellValue(boolean copyCellValue) {
  154. this.copyCellValue = copyCellValue;
  155. }
  156. /**
  157. * @return the copyCellStyle
  158. */
  159. public boolean isCopyCellStyle() {
  160. return copyCellStyle;
  161. }
  162. /**
  163. * @param copyCellStyle the copyCellStyle to set
  164. */
  165. public void setCopyCellStyle(boolean copyCellStyle) {
  166. this.copyCellStyle = copyCellStyle;
  167. }
  168. /**
  169. * @return the copyCellFormula
  170. */
  171. public boolean isCopyCellFormula() {
  172. return copyCellFormula;
  173. }
  174. /**
  175. * @param copyCellFormula the copyCellFormula to set
  176. */
  177. public void setCopyCellFormula(boolean copyCellFormula) {
  178. this.copyCellFormula = copyCellFormula;
  179. }
  180. /**
  181. * @return the copyHyperlink
  182. */
  183. public boolean isCopyHyperlink() {
  184. return copyHyperlink;
  185. }
  186. /**
  187. * @param copyHyperlink the copyHyperlink to set
  188. */
  189. public void setCopyHyperlink(boolean copyHyperlink) {
  190. this.copyHyperlink = copyHyperlink;
  191. }
  192. /**
  193. * @return the mergeHyperlink
  194. */
  195. public boolean isMergeHyperlink() {
  196. return mergeHyperlink;
  197. }
  198. /**
  199. * @param mergeHyperlink the mergeHyperlink to set
  200. */
  201. public void setMergeHyperlink(boolean mergeHyperlink) {
  202. this.mergeHyperlink = mergeHyperlink;
  203. }
  204. /*
  205. * Row-level policies
  206. */
  207. /**
  208. * @return the copyRowHeight
  209. */
  210. public boolean isCopyRowHeight() {
  211. return copyRowHeight;
  212. }
  213. /**
  214. * @param copyRowHeight the copyRowHeight to set
  215. */
  216. public void setCopyRowHeight(boolean copyRowHeight) {
  217. this.copyRowHeight = copyRowHeight;
  218. }
  219. /**
  220. * If condenseRows is true, a discontinuities in srcRows will be removed when copied to destination
  221. * For example:
  222. * Sheet.copyRows({Row(1), Row(2), Row(5)}, 11, policy) results in rows 1, 2, and 5
  223. * being copied to rows 11, 12, and 13 if condenseRows is True, or rows 11, 11, 15 if condenseRows is false
  224. * @return the condenseRows
  225. */
  226. public boolean isCondenseRows() {
  227. return condenseRows;
  228. }
  229. /**
  230. * @param condenseRows the condenseRows to set
  231. */
  232. public void setCondenseRows(boolean condenseRows) {
  233. this.condenseRows = condenseRows;
  234. }
  235. /*
  236. * Sheet-level policies
  237. */
  238. /**
  239. * @return the copyMergedRegions
  240. */
  241. public boolean isCopyMergedRegions() {
  242. return copyMergedRegions;
  243. }
  244. /**
  245. * @param copyMergedRegions the copyMergedRegions to set
  246. */
  247. public void setCopyMergedRegions(boolean copyMergedRegions) {
  248. this.copyMergedRegions = copyMergedRegions;
  249. }
  250. }