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.

ConditionalFormatting.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.util.CellRangeAddress;
  21. /**
  22. * The ConditionalFormatting class encapsulates all settings of Conditional Formatting.
  23. *
  24. * The class can be used to make a copy ConditionalFormatting settings.
  25. * <p>
  26. * For example:
  27. * <pre>{@code
  28. * ConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
  29. * newSheet.addConditionalFormatting(cf);
  30. * }</pre>
  31. *
  32. * or to modify existing Conditional Formatting settings (formatting regions and/or rules).<p>
  33. *
  34. * Use {@link org.apache.poi.ss.usermodel.Sheet#getSheetConditionalFormatting()}
  35. * to get access to an instance of this class.
  36. * <p>
  37. * To create a new Conditional Formatting set use the following approach:
  38. *
  39. * <pre>{@code
  40. *
  41. * // Define a Conditional Formatting rule, which triggers formatting
  42. * // when cell's value is greater or equal than 100.0 and
  43. * // applies patternFormatting defined below.
  44. * ConditionalFormattingRule rule = sheet.createConditionalFormattingRule(
  45. * ComparisonOperator.GE,
  46. * "100.0", // 1st formula
  47. * null // 2nd formula is not used for comparison operator GE
  48. * );
  49. *
  50. * // Create pattern with red background
  51. * PatternFormatting patternFmt = rule.cretePatternFormatting();
  52. * patternFormatting.setFillBackgroundColor(IndexedColor.RED.getIndex());
  53. *
  54. * // Define a region containing first column
  55. * Region [] regions =
  56. * {
  57. * new Region(1,(short)1,-1,(short)1)
  58. * };
  59. *
  60. * // Apply Conditional Formatting rule defined above to the regions
  61. * sheet.addConditionalFormatting(regions, rule);
  62. * }</pre>
  63. */
  64. public interface ConditionalFormatting {
  65. /**
  66. * @return array of {@code CellRangeAddress}s. Never {@code null}
  67. */
  68. CellRangeAddress[] getFormattingRanges();
  69. /**
  70. * Sets the cell ranges the rule conditional formatting must be applied to.
  71. * @param ranges non-null array of {@code CellRangeAddress}s
  72. */
  73. void setFormattingRanges(CellRangeAddress[] ranges);
  74. /**
  75. * Replaces an existing Conditional Formatting rule at position idx.
  76. * Excel pre-2007 allows to create up to 3 Conditional Formatting rules,
  77. * 2007 and later allow unlimited numbers.
  78. * This method can be useful to modify existing Conditional Formatting rules.
  79. *
  80. * @param idx position of the rule. Should be between 0 and 2 for Excel before 2007, otherwise 0+.
  81. * @param cfRule - Conditional Formatting rule
  82. */
  83. void setRule(int idx, ConditionalFormattingRule cfRule);
  84. /**
  85. * Add a Conditional Formatting rule.
  86. * Excel pre-2007 allows to create up to 3 Conditional Formatting rules.
  87. *
  88. * @param cfRule - Conditional Formatting rule
  89. */
  90. void addRule(ConditionalFormattingRule cfRule);
  91. /**
  92. * @return the Conditional Formatting rule at position idx.
  93. */
  94. ConditionalFormattingRule getRule(int idx);
  95. /**
  96. * @return number of Conditional Formatting rules.
  97. */
  98. int getNumberOfRules();
  99. }