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.

SheetConditionalFormatting.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.ss.usermodel;
  20. import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
  21. import org.apache.poi.ss.util.CellRangeAddress;
  22. /**
  23. * The 'Conditional Formatting' facet of <tt>Sheet</tt>
  24. *
  25. * @since 3.8
  26. */
  27. public interface SheetConditionalFormatting {
  28. /**
  29. * Add a new Conditional Formatting to the sheet.
  30. *
  31. * @param regions - list of rectangular regions to apply conditional formatting rules
  32. * @param rule - the rule to apply
  33. *
  34. * @return index of the newly created Conditional Formatting object
  35. */
  36. int addConditionalFormatting(CellRangeAddress[] regions,
  37. ConditionalFormattingRule rule);
  38. /**
  39. * Add a new Conditional Formatting consisting of two rules.
  40. *
  41. * @param regions - list of rectangular regions to apply conditional formatting rules
  42. * @param rule1 - the first rule
  43. * @param rule2 - the second rule
  44. *
  45. * @return index of the newly created Conditional Formatting object
  46. */
  47. int addConditionalFormatting(CellRangeAddress[] regions,
  48. ConditionalFormattingRule rule1,
  49. ConditionalFormattingRule rule2);
  50. /**
  51. * Add a new Conditional Formatting set to the sheet.
  52. *
  53. * @param regions - list of rectangular regions to apply conditional formatting rules
  54. * @param cfRules - set of up to conditional formatting rules (max 3 for Excel pre-2007)
  55. *
  56. * @return index of the newly created Conditional Formatting object
  57. */
  58. int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules);
  59. /**
  60. * Adds a copy of a ConditionalFormatting object to the sheet
  61. * <p>
  62. * This method could be used to copy ConditionalFormatting object
  63. * from one sheet to another. For example:
  64. * </p>
  65. * <pre>
  66. * ConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
  67. * newSheet.addConditionalFormatting(cf);
  68. * </pre>
  69. *
  70. * @param cf the Conditional Formatting to clone
  71. * @return index of the new Conditional Formatting object
  72. */
  73. int addConditionalFormatting(ConditionalFormatting cf);
  74. /**
  75. * A factory method allowing to create a conditional formatting rule
  76. * with a cell comparison operator
  77. * <p>
  78. * The created conditional formatting rule compares a cell value
  79. * to a formula calculated result, using the specified operator.
  80. * The type of the created condition is {@link ConditionType#CELL_VALUE_IS}
  81. * </p>
  82. *
  83. * @param comparisonOperation - MUST be a constant value from
  84. * <tt>{@link ComparisonOperator}</tt>: <p>
  85. * <ul>
  86. * <li>BETWEEN</li>
  87. * <li>NOT_BETWEEN</li>
  88. * <li>EQUAL</li>
  89. * <li>NOT_EQUAL</li>
  90. * <li>GT</li>
  91. * <li>LT</li>
  92. * <li>GE</li>
  93. * <li>LE</li>
  94. * </ul>
  95. * </p>
  96. * @param formula1 - formula for the valued, compared with the cell
  97. * @param formula2 - second formula (only used with
  98. * {@link ComparisonOperator#BETWEEN}) and {@link ComparisonOperator#NOT_BETWEEN} operations)
  99. */
  100. ConditionalFormattingRule createConditionalFormattingRule(
  101. byte comparisonOperation,
  102. String formula1,
  103. String formula2);
  104. /**
  105. * Create a conditional formatting rule that compares a cell value
  106. * to a formula calculated result, using an operator *
  107. * <p>
  108. * The type of the created condition is {@link ConditionType#CELL_VALUE_IS}
  109. * </p>
  110. *
  111. * @param comparisonOperation MUST be a constant value from
  112. * <tt>{@link ComparisonOperator}</tt> except BETWEEN and NOT_BETWEEN
  113. *
  114. * @param formula the formula to determine if the conditional formatting is applied
  115. */
  116. ConditionalFormattingRule createConditionalFormattingRule(
  117. byte comparisonOperation,
  118. String formula);
  119. /**
  120. * Create a conditional formatting rule based on a Boolean formula.
  121. * When the formula result is true, the cell is highlighted.
  122. *
  123. * <p>
  124. * The type of the created format condition is {@link ConditionType#FORMULA}
  125. * </p>
  126. * @param formula the formula to evaluate. MUST be a Boolean function.
  127. */
  128. ConditionalFormattingRule createConditionalFormattingRule(String formula);
  129. /**
  130. * Create a Databar conditional formatting rule.
  131. * <p>The thresholds and colour for it will be created, but will be
  132. * empty and require configuring with
  133. * {@link ConditionalFormattingRule#getDataBarFormatting()}
  134. * then
  135. * {@link DataBarFormatting#getMinThreshold()}
  136. * and
  137. * {@link DataBarFormatting#getMaxThreshold()}
  138. */
  139. ConditionalFormattingRule createConditionalFormattingRule(ExtendedColor color);
  140. /**
  141. * Create an Icon Set / Multi-State conditional formatting rule.
  142. * <p>The thresholds for it will be created, but will be empty
  143. * and require configuring with
  144. * {@link ConditionalFormattingRule#getMultiStateFormatting()}
  145. * then
  146. * {@link IconMultiStateFormatting#getThresholds()}
  147. */
  148. ConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet);
  149. /**
  150. * Create a Color Scale / Color Gradient conditional formatting rule.
  151. * <p>The thresholds and colours for it will be created, but will be
  152. * empty and require configuring with
  153. * {@link ConditionalFormattingRule#getColorScaleFormatting()}
  154. * then
  155. * {@link ColorScaleFormatting#getThresholds()}
  156. * and
  157. * {@link ColorScaleFormatting#getColors()}
  158. */
  159. ConditionalFormattingRule createConditionalFormattingColorScaleRule();
  160. /**
  161. * Gets Conditional Formatting object at a particular index
  162. *
  163. * @param index 0-based index of the Conditional Formatting object to fetch
  164. * @return Conditional Formatting object or <code>null</code> if not found
  165. * @throws IllegalArgumentException if the index is outside of the allowable range (0 ... numberOfFormats-1)
  166. */
  167. ConditionalFormatting getConditionalFormattingAt(int index);
  168. /**
  169. *
  170. * @return the number of conditional formats in this sheet
  171. */
  172. int getNumConditionalFormattings();
  173. /**
  174. * Removes a Conditional Formatting object by index
  175. *
  176. * @param index 0-based index of the Conditional Formatting object to remove
  177. * @throws IllegalArgumentException if the index is outside of the allowable range (0 ... numberOfFormats-1)
  178. */
  179. void removeConditionalFormatting(int index);
  180. }