From: Greg Woolsey Date: Fri, 23 Feb 2018 23:37:04 +0000 (+0000) Subject: The table auto-filter range should not include table footer rows, while the table... X-Git-Tag: REL_4_0_0_FINAL~235 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=617013a3763f4c6d3e6c86036374978a5a0c2c37;p=poi.git The table auto-filter range should not include table footer rows, while the table range does. POI was using the same for both regardless of footers. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1825182 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java index 5398c88d4b..5d84662405 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java @@ -350,6 +350,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { * Updates the reference for the cells of the table * (see Open Office XML Part 4: chapter 3.5.1.2, attribute ref) * and synchronizes any changes + * @param refs table range * * @since 3.17 beta 1 */ @@ -363,7 +364,18 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { // Update ctTable.setRef(ref); if (ctTable.isSetAutoFilter()) { - ctTable.getAutoFilter().setRef(ref); + String filterRef; + int totalsRowCount = getTotalsRowCount(); + if (totalsRowCount == 0) { + filterRef = ref; + } else { + final CellReference start = new CellReference(refs.getFirstCell().getRow(), refs.getFirstCell().getCol()); + // account for footer row(s) in auto-filter range, which doesn't include footers + final CellReference end = new CellReference(refs.getLastCell().getRow() - totalsRowCount, refs.getLastCell().getCol()); + // this won't have sheet references because we built the cell references without them + filterRef = new AreaReference(start, end, SpreadsheetVersion.EXCEL2007).formatAsString(); + } + ctTable.getAutoFilter().setRef(filterRef); } // Have everything recomputed @@ -476,7 +488,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { if (row != null && row.getCTRow().validate()) { int cellnum = firstHeaderColumn; - for (CTTableColumn col : getCTTable().getTableColumns().getTableColumnArray()) { + for (CTTableColumn col : getCTTable().getTableColumns().getTableColumnList()) { XSSFCell cell = row.getCell(cellnum); if (cell != null) { col.setName(formatter.formatCellValue(cell));