From: Yegor Kozlov Date: Thu, 2 Dec 2010 15:23:35 +0000 (+0000) Subject: Avoid crashing Excel when sorting XSSFSheet autofilter, see Bugzilla 50315 X-Git-Tag: REL_3_8_BETA1~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=18a1054792b5061113e3b1563b3f2904eef17ca1;p=poi.git Avoid crashing Excel when sorting XSSFSheet autofilter, see Bugzilla 50315 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1041407 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 80af43bf4c..a50f5afdd3 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 50315 - Avoid crashing Excel when sorting XSSFSheet autofilter 50076 - Allow access from XSSFReader to sheet comments and headers/footers 50076 - Refactor XSSFEventBasedExcelExtractor to make it easier for you to have control over outputting the cell contents 50258 - avoid corruption of XSSFWorkbook after applying XSSFRichTextRun#applyFont diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java index 1c06f8d271..ecbec23b5a 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java @@ -85,7 +85,7 @@ public final class XSSFName implements Name { *
  • 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 diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 1e887ff011..0fcd1d1103 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -2940,6 +2940,18 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { 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); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index f7af84500c..1479d768d3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -941,7 +941,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable