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
This commit is contained in:
Andrew C. Oliver 2002-07-21 03:51:43 +00:00
parent a3c338967e
commit 88ef6ef1b6
4 changed files with 122 additions and 4 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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
};
}

View File

@ -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);
}
}