poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1041407 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/
Date Thu, 02 Dec 2010 15:23:35 GMT
Author: yegor
Date: Thu Dec  2 15:23:35 2010
New Revision: 1041407

URL: http://svn.apache.org/viewvc?rev=1041407&view=rev
Log:
 Avoid crashing Excel when sorting XSSFSheet autofilter, see Bugzilla 50315

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1041407&r1=1041406&r2=1041407&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Dec  2 15:23:35 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta1" date="2010-??-??">
+           <action dev="poi-developers" type="add">50315 - Avoid crashing Excel when
sorting XSSFSheet autofilter</action>
            <action dev="poi-developers" type="add">50076 - Allow access from XSSFReader
to sheet comments and headers/footers</action>
            <action dev="poi-developers" type="add">50076 - Refactor XSSFEventBasedExcelExtractor
to make it easier for you to have control over outputting the cell contents</action>
            <action dev="poi-developers" type="fix">50258 - avoid corruption of XSSFWorkbook
after applying XSSFRichTextRun#applyFont</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java?rev=1041407&r1=1041406&r2=1041407&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java Thu Dec  2 15:23:35
2010
@@ -85,7 +85,7 @@ public final class XSSFName implements N
      * <li> This defined name refers to a range to which an AutoFilter has been
      * applied
      */
-    public final static String BUILTIN_FILTER_DB = "_xlnm._FilterDatabase:";
+    public final static String BUILTIN_FILTER_DB = "_xlnm._FilterDatabase";
 
     /**
      * A built-in defined name that refers to a consolidation area

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=1041407&r1=1041406&r2=1041407&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 Thu Dec  2 15:23:35
2010
@@ -2940,6 +2940,18 @@ public class XSSFSheet extends POIXMLDoc
         String ref = norm.formatAsString();
         af.setRef(ref);
 
+        XSSFWorkbook wb = getWorkbook();
+        int sheetIndex = getWorkbook().getSheetIndex(this);
+        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);
+        }
+
         return new XSSFAutoFilter(this);
     }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1041407&r1=1041406&r2=1041407&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Thu Dec  2 15:23:35
2010
@@ -941,7 +941,6 @@ public class XSSFWorkbook extends POIXML
         XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
         if (name == null) {
             name = createBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
-            namedRanges.add(name);
         }
         //short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
         //name.setExternSheetNumber(externSheetIndex);
@@ -1014,7 +1013,6 @@ public class XSSFWorkbook extends POIXML
         }
         if (name == null) {
             name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
-            namedRanges.add(name);
         }
 
         String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn,
startRow, endRow);
@@ -1061,7 +1059,7 @@ public class XSSFWorkbook extends POIXML
         return "$" + colRef.getCellRefParts()[2] + "$" + colRef.getCellRefParts()[1] + ":$"
+ colRef2.getCellRefParts()[2] + "$" + colRef2.getCellRefParts()[1];
     }
 
-    private XSSFName getBuiltInName(String builtInCode, int sheetNumber) {
+    XSSFName getBuiltInName(String builtInCode, int sheetNumber) {
         for (XSSFName name : namedRanges) {
             if (name.getNameName().equalsIgnoreCase(builtInCode) && name.getSheetIndex()
== sheetNumber) {
                 return name;
@@ -1077,7 +1075,7 @@ public class XSSFWorkbook extends POIXML
      * @throws IllegalArgumentException if sheetNumber is invalid
      * @throws POIXMLException if such a name already exists in the workbook
      */
-    private XSSFName createBuiltInName(String builtInName, int sheetNumber) {
+    XSSFName createBuiltInName(String builtInName, int sheetNumber) {
         validateSheetIndex(sheetNumber);
 
         CTDefinedNames names = workbook.getDefinedNames() == null ? workbook.addNewDefinedNames()
: workbook.getDefinedNames();
@@ -1092,6 +1090,7 @@ public class XSSFWorkbook extends POIXML
                         + ") already exists for sheet (" + sheetNumber + ")");
         }
 
+        namedRanges.add(name);
         return name;
     }
 

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=1041407&r1=1041406&r2=1041407&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 Thu Dec
 2 15:23:35 2010
@@ -980,10 +980,19 @@ public final class TestXSSFSheet extends
 
     public void testSetAutoFilter() {
         XSSFWorkbook wb = new XSSFWorkbook();
-        XSSFSheet sheet = wb.createSheet();
+        XSSFSheet sheet = wb.createSheet("new sheet");
         sheet.setAutoFilter(CellRangeAddress.valueOf("A1:D100"));
 
         assertEquals("A1:D100", sheet.getCTWorksheet().getAutoFilter().getRef());
+
+        // auto-filter must be registered in workboook.xml, see Bugzilla 50315
+        XSSFName nm = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0);
+        assertNotNull(nm);
+
+        assertEquals(0, nm.getCTName().getLocalSheetId());
+        assertEquals(true, nm.getCTName().getHidden());
+        assertEquals("_xlnm._FilterDatabase", nm.getCTName().getName());
+        assertEquals("'new sheet'!$A$1:$D$100", nm.getCTName().getStringValue());
     }
 
     public void testProtectSheet_lowlevel() {



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


Mime
View raw message