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

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