poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1554688 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/ss/usermodel/
Date Wed, 01 Jan 2014 22:15:45 GMT
Author: centic
Date: Wed Jan  1 22:15:44 2014
New Revision: 1554688

URL: http://svn.apache.org/r1554688
Log:
Bug 55723: Make HSSFSheet.setAutoFilter() behave equal to XSSF, also make XSSF work when setAutoFilter
is called multiple times

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1554688&r1=1554687&r2=1554688&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Wed Jan  1 22:15:44 2014
@@ -2056,8 +2056,6 @@ public final class HSSFSheet implements 
     }
 
     public HSSFAutoFilter setAutoFilter(CellRangeAddress range) {
-
-
         InternalWorkbook workbook = _workbook.getWorkbook();
         int sheetIndex = _workbook.getSheetIndex(this);
 
@@ -2067,8 +2065,15 @@ public final class HSSFSheet implements 
             name = workbook.createBuiltInName(NameRecord.BUILTIN_FILTER_DB, sheetIndex +
1);
         }
 
+        int firstRow = range.getFirstRow();
+        
+        // if row was not given when constructing the range...
+        if(firstRow == -1) {
+            firstRow = 0;
+        }
+
         // The built-in name must consist of a single Area3d Ptg.
-        Area3DPtg ptg = new Area3DPtg(range.getFirstRow(), range.getLastRow(),
+        Area3DPtg ptg = new Area3DPtg(firstRow, range.getLastRow(),
                 range.getFirstColumn(), range.getLastColumn(),
                 false, false, false, false, sheetIndex);
         name.setNameDefinition(new Ptg[]{ptg});
@@ -2084,7 +2089,7 @@ public final class HSSFSheet implements 
         HSSFPatriarch p = createDrawingPatriarch();
         for (int col = range.getFirstColumn(); col <= range.getLastColumn(); col++) {
             p.createComboBox(new HSSFClientAnchor(0, 0, 0, 0,
-                    (short) col, range.getFirstRow(), (short) (col + 1), range.getFirstRow()
+ 1));
+                    (short) col, firstRow, (short) (col + 1), firstRow + 1));
         }
 
         return new HSSFAutoFilter(this);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1554688&r1=1554687&r2=1554688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Wed Jan  1 22:15:44
2014
@@ -3194,12 +3194,13 @@ public class XSSFSheet extends POIXMLDoc
         XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
         if (name == null) {
             name = wb.createBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
-            name.getCTName().setHidden(true);
-            CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(),
true, true);
-            CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(),
true, true);
-            String fmla = r1.formatAsString() + ":" + r2.formatAsString();
-            name.setRefersToFormula(fmla);
         }
+        
+        name.getCTName().setHidden(true);
+        CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(),
true, true);
+        CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(),
true, true);
+        String fmla = r1.formatAsString() + ":" + r2.formatAsString();
+        name.setRefersToFormula(fmla);
 
         return new XSSFAutoFilter(this);
     }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1554688&r1=1554687&r2=1554688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Wed Jan
 1 22:15:44 2014
@@ -21,6 +21,7 @@ import java.util.List;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.PasswordRecord;
+import org.apache.poi.ss.usermodel.AutoFilter;
 import org.apache.poi.ss.usermodel.BaseTestSheet;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CreationHelper;
@@ -1228,4 +1229,30 @@ public final class TestXSSFSheet extends
         assertEquals("Sheet should contain 8 tables", 8, tables.size());
         assertNotNull("Sheet should contain a comments table", sheet.getCommentsTable(false));
     }
+
+    public void testBug55723b(){
+        XSSFWorkbook wb = new XSSFWorkbook();
+        Sheet sheet = wb.createSheet();
+
+        // stored with a special name
+        assertNull(wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0));
+
+        CellRangeAddress range = CellRangeAddress.valueOf("A:B");
+        AutoFilter filter = sheet.setAutoFilter(range);
+        assertNotNull(filter);
+        
+        // stored with a special name
+        XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0);
+        assertNotNull(name);
+        assertEquals("Sheet0!$A:$B", name.getRefersToFormula());
+        
+        range = CellRangeAddress.valueOf("B:C");
+        filter = sheet.setAutoFilter(range);
+        assertNotNull(filter);
+        
+        // stored with a special name
+        name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0);
+        assertNotNull(name);
+        assertEquals("Sheet0!$B:$C", name.getRefersToFormula());
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java?rev=1554688&r1=1554687&r2=1554688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java Wed Jan  1 22:15:44
2014
@@ -35,6 +35,7 @@ import org.apache.poi.hssf.record.aggreg
 import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
 import org.apache.poi.ss.formula.ptg.Area3DPtg;
 import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.usermodel.AutoFilter;
 import org.apache.poi.ss.usermodel.BaseTestSheet;
 import org.apache.poi.ss.usermodel.DataValidation;
 import org.apache.poi.ss.usermodel.DataValidationConstraint;
@@ -1066,4 +1067,20 @@ public final class TestHSSFSheet extends
         sheet.dumpDrawingRecords(true);*/
         assertNull(sheet.getDrawingEscherAggregate());
     }
+
+    public void testBug55723b() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        Sheet sheet = wb.createSheet();
+
+        // stored with a special name
+        assertNull(wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB,
1));
+
+        CellRangeAddress range = CellRangeAddress.valueOf("A:B");
+        AutoFilter filter = sheet.setAutoFilter(range);
+        assertNotNull(filter);
+        
+        // stored with a special name
+        NameRecord record = wb.getWorkbook().getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB,
1);
+        assertNotNull(record);
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java?rev=1554688&r1=1554687&r2=1554688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java Wed Jan  1 22:15:44
2014
@@ -21,6 +21,7 @@ import java.util.Iterator;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.PaneInformation;
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.SpreadsheetVersion;
@@ -800,4 +801,39 @@ public abstract class BaseTestSheet exte
         Sheet sheet = wb.createSheet();
         sheet.showInPane(2, 3);
     }
+
+
+    public void testBug55723(){
+        Workbook wb = _testDataProvider.createWorkbook();
+        Sheet sheet = wb.createSheet();
+
+        CellRangeAddress range = CellRangeAddress.valueOf("A:B");
+        AutoFilter filter = sheet.setAutoFilter(range);
+        assertNotNull(filter);
+        // there seems to be currently no generic way to check the setting...
+
+        range = CellRangeAddress.valueOf("B:C");
+        filter = sheet.setAutoFilter(range);
+        assertNotNull(filter);
+        // there seems to be currently no generic way to check the setting...
+    }
+
+    public void testBug55723_Rows() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        Sheet sheet = wb.createSheet();
+
+        CellRangeAddress range = CellRangeAddress.valueOf("A4:B55000");
+        AutoFilter filter = sheet.setAutoFilter(range);
+        assertNotNull(filter);
+    }
+
+
+    public void testBug55723d_RowsOver65k() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+        Sheet sheet = wb.createSheet();
+
+        CellRangeAddress range = CellRangeAddress.valueOf("A4:B75000");
+        AutoFilter filter = sheet.setAutoFilter(range);
+        assertNotNull(filter);
+    }
 }



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


Mime
View raw message