From: Andrew C. Oliver Date: Sun, 21 Jul 2002 03:51:43 +0000 (+0000) Subject: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10884 X-Git-Tag: REL_1_10~213 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e7dbb5dea0c079fa90ff3899895c42b05b154cfb;p=poi.git http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10884 patch to read and set margins PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352796 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/dev/BiffViewer.java b/src/java/org/apache/poi/hssf/dev/BiffViewer.java index 44e68a5d34..17399b71da 100644 --- a/src/java/org/apache/poi/hssf/dev/BiffViewer.java +++ b/src/java/org/apache/poi/hssf/dev/BiffViewer.java @@ -609,7 +609,18 @@ public class BiffViewer { case LegendRecord.sid: retval = new LegendRecord(rectype, size, data); break; - + case LeftMarginRecord.sid: + retval = new LeftMarginRecord(rectype, size, data); + break; + case RightMarginRecord.sid: + retval = new RightMarginRecord(rectype, size, data); + break; + case TopMarginRecord.sid: + retval = new TopMarginRecord(rectype, size, data); + break; + case BottomMarginRecord.sid: + retval = new BottomMarginRecord(rectype, size, data); + break; default: retval = new UnknownRecord(rectype, size, data); diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index d4edac6b39..9b88a67f98 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -91,6 +91,11 @@ import org.apache.poi.hssf.record public class Sheet extends java.lang.Object { + public static final short LeftMargin = 0; + public static final short RightMargin = 1; + public static final short TopMargin = 2; + public static final short BottomMargin = 3; + protected ArrayList records = null; int preoffset = 0; // offset of the sheet in a new file int loc = 0; @@ -2037,4 +2042,78 @@ public class Sheet WindowTwoRecord windowTwo = (WindowTwoRecord) findFirstRecordBySid(WindowTwoRecord.sid); windowTwo.setSelected(sel); } + + /** + * Gets the size of the margin in inches. + * @param margin which margin to get + * @return the size of the margin + */ + public double getMargin(short margin) { + Margin m; + switch (margin) { + case LeftMargin : + m = (Margin)findFirstRecordBySid(LeftMarginRecord.sid); + if (m == null) + return .75; + break; + case RightMargin : + m = (Margin)findFirstRecordBySid(RightMarginRecord.sid); + if (m == null) + return .75; + break; + case TopMargin : + m = (Margin)findFirstRecordBySid(TopMarginRecord.sid); + if (m == null) + return 1.0; + break; + case BottomMargin : + m = (Margin)findFirstRecordBySid(BottomMarginRecord.sid); + if (m == null) + return 1.0; + break; + default : throw new RuntimeException("Unknown margin constant: " + margin); + } + return m.getMargin(); + } + + /** + * Sets the size of the margin in inches. + * @param margin which margin to get + * @param size the size of the margin + */ + public void setMargin(short margin, double size) { + Margin m; + switch (margin) { + case LeftMargin : + m = (Margin)findFirstRecordBySid(LeftMarginRecord.sid); + if (m == null) { + m = new LeftMarginRecord(); + records.add(getDimsLoc() + 1, (Record)m); + } + break; + case RightMargin : + m = (Margin)findFirstRecordBySid(RightMarginRecord.sid); + if (m == null) { + m = new RightMarginRecord(); + records.add(getDimsLoc() + 1, (Record)m); + } + break; + case TopMargin : + m = (Margin)findFirstRecordBySid(TopMarginRecord.sid); + if (m == null) { + m = new TopMarginRecord(); + records.add(getDimsLoc() + 1, (Record)m); + } + break; + case BottomMargin : + m = (Margin)findFirstRecordBySid(BottomMarginRecord.sid); + if (m == null) { + m = new BottomMarginRecord(); + records.add(getDimsLoc() + 1, (Record)m); + } + break; + default : throw new RuntimeException("Unknown margin constant: " + margin); + } + m.setMargin(size); + } } diff --git a/src/java/org/apache/poi/hssf/record/RecordFactory.java b/src/java/org/apache/poi/hssf/record/RecordFactory.java index 7dad05d2ac..8430117ae0 100644 --- a/src/java/org/apache/poi/hssf/record/RecordFactory.java +++ b/src/java/org/apache/poi/hssf/record/RecordFactory.java @@ -107,7 +107,8 @@ public class RecordFactory LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class, MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class, FormulaRecord.class, BoolErrRecord.class, ExternSheetRecord.class, - NameRecord.class + NameRecord.class, LeftMarginRecord.class, RightMarginRecord.class, + TopMarginRecord.class, BottomMarginRecord.class }; } else { records = new Class[] @@ -135,7 +136,9 @@ public class RecordFactory WindowTwoRecord.class, SelectionRecord.class, ContinueRecord.class, LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class, MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class, - BoolErrRecord.class, ExternSheetRecord.class, NameRecord.class + BoolErrRecord.class, ExternSheetRecord.class, NameRecord.class, + LeftMarginRecord.class, RightMarginRecord.class, + TopMarginRecord.class, BottomMarginRecord.class }; } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 7e18a271d6..9229547d53 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -65,6 +65,7 @@ import org.apache.poi.hssf.record.CellValueRecordInterface; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RowRecord; import org.apache.poi.hssf.record.VCenterRecord; +import org.apache.poi.hssf.record.WindowTwoRecord; import org.apache.poi.hssf.record.WSBoolRecord; import org.apache.poi.hssf.util.Region; import org.apache.poi.util.POILogFactory; @@ -85,6 +86,12 @@ public class HSSFSheet { private static final int DEBUG = POILogger.DEBUG; + /* Constants for margins */ + public static final short LeftMargin = Sheet.LeftMargin; + public static final short RightMargin = Sheet.RightMargin; + public static final short TopMargin = Sheet.TopMargin; + public static final short BottomMargin = Sheet.BottomMargin; + /** * Used for compile-time optimization. This is the initial size for the collection of * rows. It is currently set to 20. If you generate larger sheets you may benefit @@ -792,12 +799,30 @@ public class HSSFSheet public HSSFFooter getFooter() { return new HSSFFooter(getSheet().getFooter()); } + /** * Sets whether sheet is selected. * @param sel Whether to select the sheet or deselect the sheet. */ public void setSelected(boolean sel) { getSheet().setSelected(sel); + } + /** + * Gets the size of the margin in inches. + * @param margin which margin to get + * @return the size of the margin + */ + public double getMargin(short margin) { + return getSheet().getMargin(margin); } + + /** + * Sets the size of the margin in inches. + * @param margin which margin to get + * @param size the size of the margin + */ + public void setMargin(short margin, double size) { + getSheet().setMargin(margin, size); + } }