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.

SpreadsheetVersion.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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;
  16. import org.apache.poi.ss.util.CellReference;
  17. /**
  18. * This enum allows spreadsheets from multiple Excel versions to be handled by the common code.
  19. * Properties of this enum correspond to attributes of the <i>spreadsheet</i> that are easily
  20. * discernable to the user. It is not intended to deal with low-level issues like file formats.
  21. * <p/>
  22. *
  23. * @author Josh Micich
  24. * @author Yegor Kozlov
  25. */
  26. public enum SpreadsheetVersion {
  27. /**
  28. * Excel97 format aka BIFF8
  29. * <ul>
  30. * <li>The total number of available columns is 256 (2^8)</li>
  31. * <li>The total number of available rows is 64k (2^16)</li>
  32. * <li>The maximum number of arguments to a function is 30</li>
  33. * <li>Number of conditional format conditions on a cell is 3</li>
  34. * <li>Length of text cell contents is unlimited </li>
  35. * <li>Length of text cell contents is 32767</li>
  36. * </ul>
  37. */
  38. EXCEL97(0x10000, 0x0100, 30, 3, 32767),
  39. /**
  40. * Excel2007
  41. *
  42. * <ul>
  43. * <li>The total number of available columns is 16K (2^14)</li>
  44. * <li>The total number of available rows is 1M (2^20)</li>
  45. * <li>The maximum number of arguments to a function is 255</li>
  46. * <li>Number of conditional format conditions on a cell is unlimited
  47. * (actually limited by available memory in Excel)</li>
  48. * <li>Length of text cell contents is unlimited </li>
  49. * <ul>
  50. */
  51. EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE, Integer.MAX_VALUE);
  52. private final int _maxRows;
  53. private final int _maxColumns;
  54. private final int _maxFunctionArgs;
  55. private final int _maxCondFormats;
  56. private final int _maxTextLength;
  57. private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxText) {
  58. _maxRows = maxRows;
  59. _maxColumns = maxColumns;
  60. _maxFunctionArgs = maxFunctionArgs;
  61. _maxCondFormats = maxCondFormats;
  62. _maxTextLength = maxText;
  63. }
  64. /**
  65. * @return the maximum number of usable rows in each spreadsheet
  66. */
  67. public int getMaxRows() {
  68. return _maxRows;
  69. }
  70. /**
  71. * @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>
  72. */
  73. public int getLastRowIndex() {
  74. return _maxRows - 1;
  75. }
  76. /**
  77. * @return the maximum number of usable columns in each spreadsheet
  78. */
  79. public int getMaxColumns() {
  80. return _maxColumns;
  81. }
  82. /**
  83. * @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>
  84. */
  85. public int getLastColumnIndex() {
  86. return _maxColumns - 1;
  87. }
  88. /**
  89. * @return the maximum number arguments that can be passed to a multi-arg function (e.g. COUNTIF)
  90. */
  91. public int getMaxFunctionArgs() {
  92. return _maxFunctionArgs;
  93. }
  94. /**
  95. *
  96. * @return the maximum number of conditional format conditions on a cell
  97. */
  98. public int getMaxConditionalFormats() {
  99. return _maxCondFormats;
  100. }
  101. /**
  102. *
  103. * @return the last valid column index in a ALPHA-26 representation
  104. * (<code>IV</code> or <code>XFD</code>).
  105. */
  106. public String getLastColumnName() {
  107. return CellReference.convertNumToColString(getLastColumnIndex());
  108. }
  109. /**
  110. * @return the maximum length of a text cell
  111. */
  112. public int getMaxTextLength() {
  113. return _maxTextLength;
  114. }
  115. }