From 8f5847ee8137ecb2cd9317ab0df4916a589875ed Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Sat, 7 May 2005 17:25:26 +0000 Subject: [PATCH] user API to set window pane when wb is opened by Amol Deshmukh and Li Jianming git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353676 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/model/Sheet.java | 31 +++++++++++++++++++ .../apache/poi/hssf/usermodel/HSSFSheet.java | 31 +++++++++++++++++++ .../poi/hssf/usermodel/TestHSSFSheet.java | 29 ++++++++++++++++- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 90bb59425..5784f9651 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -1934,6 +1934,37 @@ public class Sheet implements Model return retval; } + public short getTopRow() + { + return (windowTwo==null) ? (short) 0 : windowTwo.getTopRow(); + } + + public void setTopRow(short topRow) + { + if (windowTwo!=null) + { + windowTwo.setTopRow(topRow); + } + } + + /** + * Sets the left column to show in desktop window pane. + * @param the left column to show in desktop window pane + */ + public void setLeftCol(short leftCol){ + if (windowTwo!=null) + { + windowTwo.setLeftCol(leftCol); + } + } + + public short getLeftCol() + { + return (windowTwo==null) ? (short) 0 : windowTwo.getLeftCol(); + } + + + /** * Returns the active row * diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 75880ce50..d1b01ceb4 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -871,6 +871,37 @@ public class HSSFSheet sclRecord.setDenominator((short)denominator); getSheet().setSCLRecord(sclRecord); } + + /** + * The top row in the visible view when the sheet is + * first viewed after opening it in a viewer + * @return short indicating the rownum (0 based) of the top row + */ + public short getTopRow() + { + return sheet.getTopRow(); + } + + /** + * The left col in the visible view when the sheet is + * first viewed after opening it in a viewer + * @return short indicating the rownum (0 based) of the top row + */ + public short getLeftCol() + { + return sheet.getLeftCol(); + } + + /** + * Sets desktop window pane display area, when the + * file is first opened in a viewer. + * @param the top row to show in desktop window pane + * @param the left column to show in desktop window pane + */ + public void showInPane(short toprow, short leftcol){ + this.sheet.setTopRow((short)toprow); + this.sheet.setLeftCol((short)leftcol); + } /** * Shifts the merged regions left or right depending on mode diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 9afd15278..24c67dc97 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -409,7 +409,34 @@ public class TestHSSFSheet assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" ); assertEquals("DBCS Sheet Name 1", wb.getSheetName(0),"\u091c\u093e"); } - + + /** + * Testing newly added method that exposes the WINDOW2.toprow + * parameter to allow setting the toprow in the visible view + * of the sheet when it is first opened. + */ + public void testTopRow() throws Exception + { + FileInputStream fis = null; + HSSFWorkbook wb = null; + + String filename = System.getProperty("HSSF.testdata.path"); + + filename = filename + "/SimpleWithPageBreaks.xls"; + fis = new FileInputStream(filename); + wb = new HSSFWorkbook(fis); + fis.close(); + + HSSFSheet sheet = wb.getSheetAt(0); + assertNotNull(sheet); + + short toprow = (short) 100; + short leftcol = (short) 50; + sheet.showInPane(toprow,leftcol); + assertEquals("HSSFSheet.getTopRow()", toprow, sheet.getTopRow()); + assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol()); + } + public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(TestHSSFSheet.class); }