poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r761723 - in /poi/trunk/src: java/org/apache/poi/ss/SpreadsheetVersion.java java/org/apache/poi/ss/util/CellReference.java testcases/org/apache/poi/ss/TestSpreadsheetVersion.java
Date Fri, 03 Apr 2009 16:42:39 GMT
Author: yegor
Date: Fri Apr  3 16:42:39 2009
New Revision: 761723

URL: http://svn.apache.org/viewvc?rev=761723&view=rev
Log:
added SpreadsheetVersion enum to hold version-specific properties such as maximum number of
rows and columns, etc.

Added:
    poi/trunk/src/java/org/apache/poi/ss/SpreadsheetVersion.java   (with props)
    poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java

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

Propchange: poi/trunk/src/java/org/apache/poi/ss/SpreadsheetVersion.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java?rev=761723&r1=761722&r2=761723&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java Fri Apr  3 16:42:39 2009
@@ -388,7 +388,7 @@
 	 *  representation.
 	 * eg column #3 -> D
 	 */
-	protected static String convertNumToColString(int col) {
+	public static String convertNumToColString(int col) {
 		// Excel counts column A as the 1st column, we
 		//  treat it as the 0th one
 		int excelColNum = col + 1;

Added: poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java?rev=761723&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java Fri Apr  3 16:42:39
2009
@@ -0,0 +1,49 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.ss;
+
+import junit.framework.TestCase;
+
+/**
+ * Check that all enum values are properly set
+ *
+ * @author Yegor Kozlov
+ */
+public class TestSpreadsheetVersion extends TestCase {
+
+    public void testExcel97(){
+        SpreadsheetVersion v = SpreadsheetVersion.EXCEL97;
+        assertEquals(1 << 8, v.getMaxColumns());
+        assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());
+        assertEquals(1 << 16, v.getMaxRows());
+        assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());
+        assertEquals(30, v.getMaxFunctionArgs());
+        assertEquals(3, v.getMaxConditionalFormats());
+        assertEquals("IV", v.getLastColumnName());
+    }
+
+    public void testExcel2007(){
+        SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007;
+        assertEquals(1 << 14, v.getMaxColumns());
+        assertEquals(v.getMaxColumns() - 1, v.getLastColumnIndex());
+        assertEquals(1 << 20, v.getMaxRows());
+        assertEquals(v.getMaxRows() - 1, v.getLastRowIndex());
+        assertEquals(255, v.getMaxFunctionArgs());
+        assertEquals(Integer.MAX_VALUE, v.getMaxConditionalFormats());
+        assertEquals("XFD", v.getLastColumnName());
+    }
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/ss/TestSpreadsheetVersion.java
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message