diff options
author | Jason Height <jheight@apache.org> | 2006-08-29 03:27:11 +0000 |
---|---|---|
committer | Jason Height <jheight@apache.org> | 2006-08-29 03:27:11 +0000 |
commit | fdf1a81658568324b5b95e8cccc0d883fe1eb089 (patch) | |
tree | b7f370367be06def10cff66e086acfcc823c4b75 /src/java | |
parent | 4859068eb4915c534d610cb3c13ddc0f91a1052d (diff) | |
download | poi-fdf1a81658568324b5b95e8cccc0d883fe1eb089.tar.gz poi-fdf1a81658568324b5b95e8cccc0d883fe1eb089.zip |
bug 23631: support for getting the current pane information in excel
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@437930 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
5 files changed, 144 insertions, 7 deletions
diff --git a/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java b/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java index 526b8b8ffc..2d8036d830 100644 --- a/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java +++ b/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java @@ -70,6 +70,7 @@ import org.apache.poi.hssf.record.MulBlankRecord; import org.apache.poi.hssf.record.MulRKRecord; import org.apache.poi.hssf.record.NameRecord; import org.apache.poi.hssf.record.NumberRecord; +import org.apache.poi.hssf.record.PaneRecord; import org.apache.poi.hssf.record.PaletteRecord; import org.apache.poi.hssf.record.PasswordRecord; import org.apache.poi.hssf.record.PasswordRev4Record; @@ -156,7 +157,7 @@ public class EventRecordFactory LeftMarginRecord.class, RightMarginRecord.class, TopMarginRecord.class, BottomMarginRecord.class, PaletteRecord.class, StringRecord.class, SharedFormulaRecord.class, - WriteProtectRecord.class, FilePassRecord.class + WriteProtectRecord.class, FilePassRecord.class, PaneRecord.class }; } diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 01b78771a2..892f627896 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -24,6 +24,8 @@ import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate; import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate; import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate; import org.apache.poi.hssf.record.formula.Ptg; +import org.apache.poi.hssf.util.PaneInformation; + import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -2383,7 +2385,7 @@ public class Sheet implements Model } /** - * Creates a split (freezepane). + * Creates a split (freezepane). Any existing freezepane or split pane is overwritten. * @param colSplit Horizonatal position of split. * @param rowSplit Vertical position of split. * @param topRow Top row visible in bottom pane @@ -2391,6 +2393,10 @@ public class Sheet implements Model */ public void createFreezePane(int colSplit, int rowSplit, int topRow, int leftmostColumn ) { + int paneLoc = findFirstRecordLocBySid(PaneRecord.sid); + if (paneLoc != -1) + records.remove(paneLoc); + int loc = findFirstRecordLocBySid(WindowTwoRecord.sid); PaneRecord pane = new PaneRecord(); pane.setX((short)colSplit); @@ -2422,7 +2428,7 @@ public class Sheet implements Model } /** - * Creates a split pane. + * Creates a split pane. Any existing freezepane or split pane is overwritten. * @param xSplitPos Horizonatal position of split (in 1/20th of a point). * @param ySplitPos Vertical position of split (in 1/20th of a point). * @param topRow Top row visible in bottom pane @@ -2436,6 +2442,10 @@ public class Sheet implements Model */ public void createSplitPane(int xSplitPos, int ySplitPos, int topRow, int leftmostColumn, int activePane ) { + int paneLoc = findFirstRecordLocBySid(PaneRecord.sid); + if (paneLoc != -1) + records.remove(paneLoc); + int loc = findFirstRecordLocBySid(WindowTwoRecord.sid); PaneRecord r = new PaneRecord(); r.setX((short)xSplitPos); @@ -2452,6 +2462,19 @@ public class Sheet implements Model sel.setPane(PANE_LOWER_RIGHT); } + + /** + * Returns the information regarding the currently configured pane (split or freeze). + * @return null if no pane configured, or the pane information. + */ + public PaneInformation getPaneInformation() { + PaneRecord rec = (PaneRecord)findFirstRecordBySid(PaneRecord.sid); + if (rec == null) + return null; + + return new PaneInformation(rec.getX(), rec.getY(), rec.getTopRow(), + rec.getLeftColumn(), (byte)rec.getActivePane(), windowTwo.getFreezePanes()); + } public SelectionRecord getSelection() { diff --git a/src/java/org/apache/poi/hssf/record/RecordFactory.java b/src/java/org/apache/poi/hssf/record/RecordFactory.java index 89ce3ba254..c6ea252bb0 100644 --- a/src/java/org/apache/poi/hssf/record/RecordFactory.java +++ b/src/java/org/apache/poi/hssf/record/RecordFactory.java @@ -72,7 +72,7 @@ public class RecordFactory ObjRecord.class, TextObjectRecord.class, PaletteRecord.class, StringRecord.class, RecalcIdRecord.class, SharedFormulaRecord.class, HorizontalPageBreakRecord.class, VerticalPageBreakRecord.class, - WriteProtectRecord.class, FilePassRecord.class + WriteProtectRecord.class, FilePassRecord.class, PaneRecord.class }; } private static Map recordsMap = recordsToMap(records); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index c7befce1be..99a2b5fef3 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -26,6 +26,7 @@ import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.*; import org.apache.poi.hssf.util.Region; +import org.apache.poi.hssf.util.PaneInformation; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -1076,7 +1077,7 @@ public class HSSFSheet } /** - * Creates a split (freezepane). + * Creates a split (freezepane). Any existing freezepane or split pane is overwritten. * @param colSplit Horizonatal position of split. * @param rowSplit Vertical position of split. * @param topRow Top row visible in bottom pane @@ -1092,7 +1093,7 @@ public class HSSFSheet } /** - * Creates a split (freezepane). + * Creates a split (freezepane). Any existing freezepane or split pane is overwritten. * @param colSplit Horizonatal position of split. * @param rowSplit Vertical position of split. */ @@ -1102,7 +1103,7 @@ public class HSSFSheet } /** - * Creates a split pane. + * Creates a split pane. Any existing freezepane or split pane is overwritten. * @param xSplitPos Horizonatal position of split (in 1/20th of a point). * @param ySplitPos Vertical position of split (in 1/20th of a point). * @param topRow Top row visible in bottom pane @@ -1118,6 +1119,14 @@ public class HSSFSheet { getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane ); } + + /** + * Returns the information regarding the currently configured pane (split or freeze). + * @return null if no pane configured, or the pane information. + */ + public PaneInformation getPaneInformation() { + return getSheet().getPaneInformation(); + } /** * Sets whether the gridlines are shown in a viewer. diff --git a/src/java/org/apache/poi/hssf/util/PaneInformation.java b/src/java/org/apache/poi/hssf/util/PaneInformation.java new file mode 100644 index 0000000000..4d5eeeeeec --- /dev/null +++ b/src/java/org/apache/poi/hssf/util/PaneInformation.java @@ -0,0 +1,104 @@ +/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.util;
+
+/**
+ * Holds information regarding a split plane or freeze plane for a sheet.
+ *
+ */
+public class PaneInformation
+{
+ /** Constant for active pane being the lower right*/
+ public static final byte PANE_LOWER_RIGHT = (byte)0;
+ /** Constant for active pane being the upper right*/
+ public static final byte PANE_UPPER_RIGHT = (byte)1;
+ /** Constant for active pane being the lower left*/
+ public static final byte PANE_LOWER_LEFT = (byte)2;
+ /** Constant for active pane being the upper left*/
+ public static final byte PANE_UPPER_LEFT = (byte)3;
+
+ private short x;
+ private short y;
+ private short topRow;
+ private short leftColumn;
+ private byte activePane;
+ private boolean frozen = false;
+
+ public PaneInformation(short x, short y, short top, short left, byte active, boolean frozen) {
+ this.x = x;
+ this.y = y;
+ this.topRow = top;
+ this.leftColumn = left;
+ this.activePane = active;
+ this.frozen = frozen;
+ }
+
+
+ /**
+ * Returns the vertical position of the split.
+ * @return 0 if there is no vertical spilt,
+ * or for a freeze pane the number of columns in the TOP pane,
+ * or for a split plane the position of the split in 1/20th of a point.
+ */
+ public short getVerticalSplitPosition() {
+ return x;
+ }
+
+ /**
+ * Returns the horizontal position of the split.
+ * @return 0 if there is no horizontal spilt,
+ * or for a freeze pane the number of rows in the LEFT pane,
+ * or for a split plane the position of the split in 1/20th of a point.
+ */
+ public short getHorizontalSplitPosition() {
+ return y;
+ }
+
+ /**
+ * For a horizontal split returns the top row in the BOTTOM pane.
+ * @return 0 if there is no horizontal split, or the top row of the bottom pane.
+ */
+ public short getHorizontalSplitTopRow() {
+ return topRow;
+ }
+
+ /**
+ * For a vertical split returns the left column in the RIGHT pane.
+ * @return 0 if there is no vertical split, or the left column in the RIGHT pane.
+ */
+ public short getVerticalSplitLeftColumn() {
+ return leftColumn;
+ }
+
+ /**
+ * Returns the active pane
+ * @see PANE_LOWER_RIGHT
+ * @see PANE_UPPER_RIGHT
+ * @see PANE_LOWER_LEFT
+ * @see PANE_UPPER_LEFT
+ * @return the active pane.
+ */
+ public byte getActivePane() {
+ return activePane;
+ }
+
+ /** Returns true if this is a Freeze pane, false if it is a split pane.
+ */
+ public boolean isFreezePane() {
+ return frozen;
+ }
+}
|