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.

XSSFConditionalFormattingThreshold.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.xssf.usermodel;
  20. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo;
  21. import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfvoType;
  22. /**
  23. * High level representation for Icon / Multi-State / Databar /
  24. * Colour Scale change thresholds
  25. */
  26. public class XSSFConditionalFormattingThreshold implements org.apache.poi.ss.usermodel.ConditionalFormattingThreshold {
  27. private final CTCfvo cfvo;
  28. protected XSSFConditionalFormattingThreshold(CTCfvo cfvo) {
  29. this.cfvo = cfvo;
  30. }
  31. protected CTCfvo getCTCfvo() {
  32. return cfvo;
  33. }
  34. @Override
  35. public RangeType getRangeType() {
  36. return RangeType.byName(cfvo.getType().toString());
  37. }
  38. @Override
  39. public void setRangeType(RangeType type) {
  40. STCfvoType.Enum xtype = STCfvoType.Enum.forString(type.name);
  41. cfvo.setType(xtype);
  42. }
  43. @Override
  44. public String getFormula() {
  45. if (cfvo.getType() == STCfvoType.FORMULA) {
  46. return cfvo.getVal();
  47. }
  48. return null;
  49. }
  50. @Override
  51. public void setFormula(String formula) {
  52. cfvo.setVal(formula);
  53. }
  54. @Override
  55. public Double getValue() {
  56. if (cfvo.getType() == STCfvoType.FORMULA ||
  57. cfvo.getType() == STCfvoType.MIN ||
  58. cfvo.getType() == STCfvoType.MAX) {
  59. return null;
  60. }
  61. if (cfvo.isSetVal()) {
  62. return Double.parseDouble(cfvo.getVal());
  63. } else {
  64. return null;
  65. }
  66. }
  67. @Override
  68. public void setValue(Double value) {
  69. if (value == null) {
  70. cfvo.unsetVal();
  71. } else {
  72. cfvo.setVal(value.toString());
  73. }
  74. }
  75. /**
  76. * @return true if 'gte' attribute is set to true (defaults to true)
  77. * @since POI 5.2.3
  78. */
  79. public boolean isGte() {
  80. return cfvo.getGte();
  81. }
  82. /**
  83. * @param gte set 'gte' attribute (defaults to true)
  84. * @since POI 5.2.3
  85. */
  86. public void setGte(boolean gte) {
  87. cfvo.setGte(gte);
  88. }
  89. }