From de67c0809e3ecdd5f8a0565dd7c81834bc3b6bf3 Mon Sep 17 00:00:00 2001 From: Paolo Mottadelli Date: Mon, 7 Apr 2008 19:54:43 +0000 Subject: [PATCH] XSSFSheet freeze/splitPane support + tests git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645662 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFSheet.java | 26 ++++++++++++++----- .../poi/xssf/usermodel/TestXSSFSheet.java | 19 ++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) 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 9ffa8947ba..96ffe3c03a 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -53,6 +53,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPane; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection; @@ -63,6 +64,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPaneState; public class XSSFSheet implements Sheet { @@ -205,13 +208,15 @@ public class XSSFSheet implements Sheet { } public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow) { - // TODO Auto-generated method stub - + this.createFreezePane(colSplit, rowSplit); + this.showInPane((short)topRow, (short)leftmostColumn); } public void createFreezePane(int colSplit, int rowSplit) { - // TODO Auto-generated method stub - + getPane().setXSplit(colSplit); + getPane().setYSplit(rowSplit); + // make bottomRight default active pane + getPane().setActivePane(STPane.BOTTOM_RIGHT); } /** @@ -250,9 +255,9 @@ public class XSSFSheet implements Sheet { return xrow; } - public void createSplitPane(int splitPos, int splitPos2, int leftmostColumn, int topRow, int activePane) { - // TODO Auto-generated method stub - + public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) { + createFreezePane(xSplitPos, ySplitPos, leftmostColumn, topRow); + getPane().setActivePane(STPane.Enum.forInt(activePane)); } public void dumpDrawingRecords(boolean fat) { @@ -1017,4 +1022,11 @@ public class XSSFSheet implements Sheet { } return false; } + + private CTPane getPane() { + if (getDefaultSheetView().getPane() == null) { + getDefaultSheetView().addNewPane(); + } + return getDefaultSheetView().getPane(); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 4b9abe2514..e92d5d0657 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -30,6 +30,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPaneState; public class TestXSSFSheet extends TestCase { @@ -529,6 +531,23 @@ public class TestXSSFSheet extends TestCase { } + public void testCreateFreezePane() { + Workbook workbook = new XSSFWorkbook(); + CTSheet ctSheet = CTSheet.Factory.newInstance(); + CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance(); + XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook); + sheet.createFreezePane(2, 4); + assertEquals((double)2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit()); + assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); + sheet.createFreezePane(3, 6, 10, 10); + assertEquals((double)3, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit()); + assertEquals(10, sheet.getTopRow()); + assertEquals(10, sheet.getLeftCol()); + sheet.createSplitPane(4, 8, 12, 12, 1); + assertEquals((double)8, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getYSplit()); + assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); + } + private XSSFSheet createSheet(XSSFWorkbook workbook, String name) { XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name); -- 2.39.5