diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 80af43bf4..a50f5afdd 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 1c06f8d27..ecbec23b5 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 1e887ff01..0fcd1d110 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 f7af84500..1479d768d 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