diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 6651b10f2..f6b693360 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 50884 - XSSF and HSSF freeze panes now behave the same Support for adding a table to a XSSFSheet Improve HSMF MAPIMessage access to the HTML and RTF versions of the message body (where available) Add new method to HSMF of MAPIMessage.has7BitEncodingStrings() to make it easier to decide when encoding guessing is needed 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 80cfd9147..2d8ccf970 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -443,14 +443,23 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow) { CTPane pane = getPane(); - if (colSplit > 0) pane.setXSplit(colSplit); - if (rowSplit > 0) pane.setYSplit(rowSplit); + if (colSplit > 0) { + pane.setXSplit(colSplit); + } else { + pane.unsetXSplit(); + } + if (rowSplit > 0) { + pane.setYSplit(rowSplit); + } else { + pane.unsetYSplit(); + } + pane.setState(STPaneState.FROZEN); if (rowSplit == 0) { - pane.setTopLeftCell(new CellReference(0, topRow).formatAsString()); + pane.setTopLeftCell(new CellReference(0, leftmostColumn).formatAsString()); pane.setActivePane(STPane.TOP_RIGHT); } else if (colSplit == 0) { - pane.setTopLeftCell(new CellReference(rowSplit, 0).formatAsString()); + pane.setTopLeftCell(new CellReference(topRow, 0).formatAsString()); pane.setActivePane(STPane.BOTTOM_LEFT); } else { pane.setTopLeftCell(new CellReference(topRow, leftmostColumn).formatAsString()); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index cf873f4d8..835b38627 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -999,6 +999,29 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { assertEquals(rowSplit, paneInfo.getHorizontalSplitPosition()); assertEquals(leftmostColumn, paneInfo.getVerticalSplitLeftColumn()); assertEquals(topRow, paneInfo.getHorizontalSplitTopRow()); + + + // Now a row only freezepane + s.createFreezePane(0, 3); + paneInfo = s.getPaneInformation(); + + assertEquals(0, paneInfo.getVerticalSplitPosition()); + assertEquals(3, paneInfo.getHorizontalSplitPosition()); + if(wb == wbs[0]) { + assertEquals(64, paneInfo.getVerticalSplitLeftColumn()); // HSSF + } else { + assertEquals(0, paneInfo.getVerticalSplitLeftColumn()); // XSSF + } + assertEquals(3, paneInfo.getHorizontalSplitTopRow()); + + // Now a column only freezepane + s.createFreezePane(4, 0); + paneInfo = s.getPaneInformation(); + + assertEquals(4, paneInfo.getVerticalSplitPosition()); + assertEquals(0, paneInfo.getHorizontalSplitPosition()); + assertEquals(4 , paneInfo.getVerticalSplitLeftColumn()); + assertEquals(0, paneInfo.getHorizontalSplitTopRow()); } } }