--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.ss;\r
+\r
+import org.apache.poi.ss.util.CellReference;\r
+\r
+/**\r
+ * This enum allows spreadsheets from multiple Excel versions to be handled by the common code.\r
+ * Properties of this enum correspond to attributes of the <i>spreadsheet</i> that are easily\r
+ * discernable to the user. It is not intended to deal with low-level issues like file formats. \r
+ * <p/>\r
+ * \r
+ * For internal POI use only\r
+ * \r
+ * @author Josh Micich\r
+ * @author Yegor Kozlov\r
+ */\r
+public enum SpreadsheetVersion {\r
+ /**\r
+ * Excel97 format aka BIFF8\r
+ * <ul>\r
+ * <li>The total number of available columns is 256 (2^8)</li>\r
+ * <li>The total number of available rows is 64k (2^16)</li>\r
+ * <li>The maximum number of arguments to a function is 30</li>\r
+ * <li>Number of conditional format conditions on a cell is 3</li>\r
+ * </ul>\r
+ */\r
+ EXCEL97(0x10000, 0x0100, 30, 3),\r
+\r
+ /**\r
+ * Excel2007\r
+ *\r
+ * <ul>\r
+ * <li>The total number of available columns is 16K (2^14)</li>\r
+ * <li>The total number of available rows is 1M (2^20)</li>\r
+ * <li>The maximum number of arguments to a function is 255</li>\r
+ * <li>Number of conditional format conditions on a cell is unlimited\r
+ * (actually limited by available memory in Excel)</li>\r
+ * <ul>\r
+ */\r
+ EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE);\r
+\r
+ private final int _maxRows;\r
+ private final int _maxColumns;\r
+ private final int _maxFunctionArgs;\r
+ private final int _maxCondFormats;\r
+\r
+ private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats) {\r
+ _maxRows = maxRows;\r
+ _maxColumns = maxColumns;\r
+ _maxFunctionArgs = maxFunctionArgs;\r
+ _maxCondFormats = maxCondFormats;\r
+ }\r
+\r
+ /**\r
+ * @return the maximum number of usable rows in each spreadsheet\r
+ */\r
+ public int getMaxRows() {\r
+ return _maxRows;\r
+ }\r
+\r
+ /**\r
+ * @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>\r
+ */\r
+ public int getLastRowIndex() {\r
+ return _maxRows - 1;\r
+ }\r
+\r
+ /**\r
+ * @return the maximum number of usable columns in each spreadsheet\r
+ */\r
+ public int getMaxColumns() {\r
+ return _maxColumns;\r
+ }\r
+\r
+ /**\r
+ * @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>\r
+ */\r
+ public int getLastColumnIndex() {\r
+ return _maxColumns - 1;\r
+ }\r
+\r
+ /**\r
+ * @return the maximum number arguments that can be passed to a multi-arg\r
+ * function (e.g. COUNTIF)\r
+ */\r
+ public int getMaxFunctionArgs() {\r
+ return _maxFunctionArgs;\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @return the maximum number of conditional format conditions on a cell\r
+ */\r
+ public int getMaxConditionalFormats() {\r
+ return _maxCondFormats;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return the last valid column index in a ALPHA-26 representation\r
+ * ( <code>IV</code> or <code>XFD</code>).\r
+ */\r
+ public String getLastColumnName() {\r
+ return CellReference.convertNumToColString(getLastColumnIndex());\r
+ }\r
+}\r
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.ss;\r
+\r
+import junit.framework.TestCase;\r
+\r
+/**\r
+ * Check that all enum values are properly set\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestSpreadsheetVersion extends TestCase {\r
+\r
+ public void testExcel97(){\r
+ SpreadsheetVersion v = SpreadsheetVersion.EXCEL97;\r
+ assertEquals(1 << 8, v.getMaxColumns());\r
+ assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());\r
+ assertEquals(1 << 16, v.getMaxRows());\r
+ assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());\r
+ assertEquals(30, v.getMaxFunctionArgs());\r
+ assertEquals(3, v.getMaxConditionalFormats());\r
+ assertEquals("IV", v.getLastColumnName());\r
+ }\r
+\r
+ public void testExcel2007(){\r
+ SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007;\r
+ assertEquals(1 << 14, v.getMaxColumns());\r
+ assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());\r
+ assertEquals(1 << 20, v.getMaxRows());\r
+ assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());\r
+ assertEquals(255, v.getMaxFunctionArgs());\r
+ assertEquals(Integer.MAX_VALUE, v.getMaxConditionalFormats());\r
+ assertEquals("XFD", v.getLastColumnName());\r
+ }\r
+}\r