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.

FormulaType.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.formula;
  16. import org.apache.poi.util.Internal;
  17. /**
  18. * Enumeration of various formula types.
  19. *
  20. * See Sections 3 and 4.8 of https://www.openoffice.org/sc/excelfileformat.pdf
  21. */
  22. @Internal
  23. public enum FormulaType {
  24. /** Regular cell formula */
  25. CELL(true),
  26. /**
  27. * A Shared Formula ("{=SUM(A1:E1*{1,2,3,4,5}}")
  28. *
  29. * Similar to an array formula, but stored in a SHAREDFMLA instead of ARRAY record as a file size optimization.
  30. * See Section 4.8 of https://www.openoffice.org/sc/excelfileformat.pdf
  31. */
  32. SHARED(true),
  33. /**
  34. * An Array formula ("{=SUM(A1:E1*{1,2,3,4,5}}")
  35. * https://support.office.com/en-us/article/Guidelines-and-examples-of-array-formulas-7D94A64E-3FF3-4686-9372-ECFD5CAA57C7
  36. */
  37. ARRAY(false),
  38. /** Conditional formatting */
  39. CONDFORMAT(true),
  40. /** Named range */
  41. NAMEDRANGE(false),
  42. /**
  43. * This constant is currently very specific. The exact differences from general data
  44. * validation formulas or conditional format formulas is not known yet
  45. */
  46. DATAVALIDATION_LIST(false);
  47. /** formula is expected to return a single value vs. multiple values */
  48. private final boolean isSingleValue ;
  49. /**
  50. * @since POI 3.15 beta 3.
  51. */
  52. private FormulaType(boolean singleValue) {
  53. this.isSingleValue = singleValue;
  54. }
  55. /**
  56. * @return true if this formula type only returns single values, false if it can return multiple values (arrays, ranges, etc.)
  57. */
  58. public boolean isSingleValue() {
  59. return isSingleValue;
  60. }
  61. /**
  62. * Used to transition from <code>int</code>s (possibly stored in the Excel file) to <code>FormulaType</code>s.
  63. * @param code
  64. * @return FormulaType
  65. * @throws IllegalArgumentException if code is out of range
  66. * @since POI 3.15 beta 3.
  67. */
  68. public static FormulaType forInt(int code) {
  69. if (code >= 0 && code < values().length) {
  70. return values()[code];
  71. }
  72. throw new IllegalArgumentException("Invalid FormulaType code: " + code);
  73. }
  74. }