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);
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;
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);
+ }
}
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[]
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
};
}
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;
{
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
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);
+ }
}