]> source.dussan.org Git - poi.git/commitdiff
Bug 55723: Make HSSFSheet.setAutoFilter() behave equal to XSSF, also make XSSF work...
authorDominik Stadler <centic@apache.org>
Wed, 1 Jan 2014 22:15:44 +0000 (22:15 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 1 Jan 2014 22:15:44 +0000 (22:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1554688 13f79535-47bb-0310-9956-ffa450edef68

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

index 6cc2ca9fb5d8ec6ee63b17fe8c59b2762f583a5b..b57588ebfbda6d4737605b439b0a7a8502de57e0 100644 (file)
@@ -2056,8 +2056,6 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
     }
 
     public HSSFAutoFilter setAutoFilter(CellRangeAddress range) {
-
-
         InternalWorkbook workbook = _workbook.getWorkbook();
         int sheetIndex = _workbook.getSheetIndex(this);
 
@@ -2067,8 +2065,15 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
             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 org.apache.poi.ss.usermodel.Sheet {
         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);
index afa56a57715cfbea9037ddde7ca04d66c7374811..1e8b64130c9625235289d8e79097048dd1a7c5e6 100644 (file)
@@ -3194,12 +3194,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
         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);
     }
index 047fe9c1825fd28fba1616785dba1cfad005517f..329283cc38ba44728f10cb9e2e4d78685f7dbb8d 100644 (file)
@@ -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 BaseTestSheet {
         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());
+    }
 }
index c2a579d2661f890bb5135c40965f9b1ea77c11d5..9aa16d843a55b7c18b789b7491cce413e76f6b9f 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
 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 BaseTestSheet {
         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);
+    }
 }
index 4c37017e5cd2eba9d204dd849725275c69a47b92..370b1c121c2e28f4e5ce9f1393a3f0420463d271 100644 (file)
@@ -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 extends TestCase {
         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);
+    }
 }