poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1747762 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/usermodel/XSSFTable.java testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Date Fri, 10 Jun 2016 18:10:53 GMT
Author: onealj
Date: Fri Jun 10 18:10:52 2016
New Revision: 1747762

URL: http://svn.apache.org/viewvc?rev=1747762&view=rev
Log:
bug 57840: add unit test for XSSFTable.findColumnIndex

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java?rev=1747762&r1=1747761&r2=1747762&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java Fri Jun 10 18:10:52
2016
@@ -335,12 +335,15 @@ public class XSSFTable extends POIXMLDoc
      * The column index is relative to the left-most column in the table, 0-indexed.
      * Returns <code>-1</code> if <code>column</code> is not a header
name in table.
      *
+     * Column Header names are case-insensitive
+     *
      * Note: this function caches column names for performance. To flush the cache (because
columns
      * have been moved or column headers have been changed), {@link #updateHeaders()} must
be called.
      *
      * @since 3.15 beta 2
      */
-    public int findColumnIndex(String column) {
+    public int findColumnIndex(String columnHeader) {
+        if (columnHeader == null) return -1;
         if (columnMap == null) {
             // FIXME: replace with org.apache.commons.collections.map.CaseInsensitiveMap
             int count = getTableColumns().length;
@@ -353,7 +356,7 @@ public class XSSFTable extends POIXMLDoc
         }
         // Table column names with special characters need a single quote escape
         // but the escape is not present in the column definition
-        Integer idx = columnMap.get(caseInsensitive(column.replace("'", "")));
+        Integer idx = columnMap.get(caseInsensitive(columnHeader.replace("'", "")));
         return idx == null ? -1 : idx.intValue();
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1747762&r1=1747761&r2=1747762&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Fri Jun
10 18:10:52 2016
@@ -18,6 +18,7 @@
 package org.apache.poi.xssf.usermodel;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -110,4 +111,27 @@ public final class TestXSSFTable {
         outputWorkbook.close();
     }
 
-}
\ No newline at end of file
+    @Test
+    public void findColumnIndex() throws IOException {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx");
+        // FIXME: use a worksheet where upper left cell of table is not A1 so that we test
+        // that XSSFTable.findColumnIndex returns the column index relative to the first
+        // column in the table, not the column number in the sheet
+
+        XSSFTable table = wb.getTable("\\_Prime.1");
+        assertNotNull(table);
+        assertEquals(0, table.findColumnIndex("calc='#*'#"));
+        assertEquals(1, table.findColumnIndex("Name"));
+        assertEquals(2, table.findColumnIndex("Number"));
+
+        assertEquals("case insensitive", 2, table.findColumnIndex("NuMbEr"));
+
+        // findColumnIndex should return -1 if no column header name matches
+        assertEquals(-1, table.findColumnIndex(null));
+        assertEquals(-1, table.findColumnIndex(""));
+        assertEquals(-1, table.findColumnIndex("one"));
+
+        wb.close();
+    }
+
+}



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


Mime
View raw message