Bugzilla 52574 - support setting header / footer page margins in HSSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1294181 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2012-02-27 15:22:22 +00:00
parent 828ee0cf88
commit be4f4d11a8
4 changed files with 26 additions and 3 deletions

View File

@ -34,6 +34,8 @@
<changes> <changes>
<release version="3.8-beta6" date="2012-??-??"> <release version="3.8-beta6" date="2012-??-??">
<action dev="poi-developers" type="add">52574 - support setting header / footer page margins in HSSF </action>
<action dev="poi-developers" type="add">52583 - fixed WorkbookUtil#createSafeSheetName to escape colon </action>
<action dev="poi-developers" type="add">51710 - fixed reading shared formulas in XSSF </action> <action dev="poi-developers" type="add">51710 - fixed reading shared formulas in XSSF </action>
<action dev="poi-developers" type="add">52708 - misc improvements in CellFormat </action> <action dev="poi-developers" type="add">52708 - misc improvements in CellFormat </action>
<action dev="poi-developers" type="add">52690 - added a getter for length of encrypted data in Ecma and Agile decryptors</action> <action dev="poi-developers" type="add">52690 - added a getter for length of encrypted data in Ecma and Agile decryptors</action>

View File

@ -1062,7 +1062,14 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
* @return the size of the margin * @return the size of the margin
*/ */
public double getMargin(short margin) { public double getMargin(short margin) {
return _sheet.getPageSettings().getMargin(margin); switch (margin){
case FooterMargin:
return _sheet.getPageSettings().getPrintSetup().getFooterMargin();
case HeaderMargin:
return _sheet.getPageSettings().getPrintSetup().getHeaderMargin();
default:
return _sheet.getPageSettings().getMargin(margin);
}
} }
/** /**
@ -1071,7 +1078,16 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
* @param size the size of the margin * @param size the size of the margin
*/ */
public void setMargin(short margin, double size) { public void setMargin(short margin, double size) {
_sheet.getPageSettings().setMargin(margin, size); switch (margin){
case FooterMargin:
_sheet.getPageSettings().getPrintSetup().setFooterMargin(size);
break;
case HeaderMargin:
_sheet.getPageSettings().getPrintSetup().setHeaderMargin(size);
break;
default:
_sheet.getPageSettings().setMargin(margin, size);
}
} }
private WorksheetProtectionBlock getProtectionBlock() { private WorksheetProtectionBlock getProtectionBlock() {

View File

@ -2673,7 +2673,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
CTCellFormula sf = (CTCellFormula)f.copy(); CTCellFormula sf = (CTCellFormula)f.copy();
CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef()); CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef());
CellReference cellRef = new CellReference(cell); CellReference cellRef = new CellReference(cell);
// If the shared formula range preceeds the master cell then the preseeing part is discarded, e.g. // If the shared formula range preceeds the master cell then the preceding part is discarded, e.g.
// if the cell is E60 and the shared formula range is C60:M85 then the effective range is E60:M85 // if the cell is E60 and the shared formula range is C60:M85 then the effective range is E60:M85
// see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710 // see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710
if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){ if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){

View File

@ -557,6 +557,11 @@ public abstract class BaseTestSheet extends TestCase {
sheet.setMargin(Sheet.BottomMargin, 13.0); sheet.setMargin(Sheet.BottomMargin, 13.0);
assertEquals(13.0, sheet.getMargin(Sheet.BottomMargin), 0.0); assertEquals(13.0, sheet.getMargin(Sheet.BottomMargin), 0.0);
sheet.setMargin(Sheet.FooterMargin, 5.6);
assertEquals(5.6, sheet.getMargin(Sheet.FooterMargin), 0.0);
sheet.setMargin(Sheet.HeaderMargin, 11.5);
assertEquals(11.5, sheet.getMargin(Sheet.HeaderMargin), 0.0);
// incorrect margin constant // incorrect margin constant
try { try {
sheet.setMargin((short) 65, 15); sheet.setMargin((short) 65, 15);