Improve support, tests and documentation for xssf headers and footers
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@682662 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1acb09f9bd
commit
cd56a91ef9
@ -392,13 +392,17 @@ public interface Sheet extends Iterable<Row> {
|
||||
PrintSetup getPrintSetup();
|
||||
|
||||
/**
|
||||
* Gets the user model for the document header.
|
||||
* Gets the user model for the default document header.
|
||||
* Note that XSSF offers more kinds of document
|
||||
* headers than HSSF does
|
||||
* @return The Document header.
|
||||
*/
|
||||
Header getHeader();
|
||||
|
||||
/**
|
||||
* Gets the user model for the document footer.
|
||||
* Gets the user model for the default document footer.
|
||||
* Note that XSSF offers more kinds of document
|
||||
* footers than HSSF does.
|
||||
* @return The Document footer.
|
||||
*/
|
||||
Footer getFooter();
|
||||
|
@ -32,7 +32,11 @@ public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
getHeaderFooter().setEvenFooter(text);
|
||||
if(text == null) {
|
||||
getHeaderFooter().unsetEvenFooter();
|
||||
} else {
|
||||
getHeaderFooter().setEvenFooter(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,11 @@ public class XSSFEvenHeader extends XSSFHeaderFooter implements Header{
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
getHeaderFooter().setEvenHeader(text);
|
||||
if(text == null) {
|
||||
getHeaderFooter().unsetEvenHeader();
|
||||
} else {
|
||||
getHeaderFooter().setEvenHeader(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,10 @@ public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
getHeaderFooter().setFirstFooter(text);
|
||||
if(text == null) {
|
||||
getHeaderFooter().unsetFirstFooter();
|
||||
} else {
|
||||
getHeaderFooter().setFirstFooter(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,11 @@ public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
getHeaderFooter().setFirstHeader(text);
|
||||
if(text == null) {
|
||||
getHeaderFooter().unsetFirstHeader();
|
||||
} else {
|
||||
getHeaderFooter().setFirstHeader(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,10 @@ public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
getHeaderFooter().setOddFooter(text);
|
||||
if(text == null) {
|
||||
getHeaderFooter().unsetOddFooter();
|
||||
} else {
|
||||
getHeaderFooter().setOddFooter(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,10 @@ public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
getHeaderFooter().setOddHeader(text);
|
||||
if(text == null) {
|
||||
getHeaderFooter().unsetOddHeader();
|
||||
} else {
|
||||
getHeaderFooter().setOddHeader(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -381,14 +381,7 @@ public class XSSFSheet implements Sheet {
|
||||
return getSheetTypePageSetUpPr().getFitToPage();
|
||||
}
|
||||
|
||||
public Footer getFooter() {
|
||||
return getOddFooter();
|
||||
}
|
||||
|
||||
public Footer getOddFooter() {
|
||||
return new XSSFOddFooter(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
protected CTHeaderFooter getSheetTypeHeaderFooter() {
|
||||
if (worksheet.getHeaderFooter() == null) {
|
||||
worksheet.setHeaderFooter(CTHeaderFooter.Factory.newInstance());
|
||||
@ -396,31 +389,80 @@ public class XSSFSheet implements Sheet {
|
||||
return worksheet.getHeaderFooter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default footer for the sheet,
|
||||
* creating one as needed.
|
||||
* You may also want to look at
|
||||
* {@link #getFirstFooter()},
|
||||
* {@link #getOddFooter()} and
|
||||
* {@link #getEvenFooter()}
|
||||
*/
|
||||
public Footer getFooter() {
|
||||
// The default footer is an odd footer
|
||||
return getOddFooter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default header for the sheet,
|
||||
* creating one as needed.
|
||||
* You may also want to look at
|
||||
* {@link #getFirstHeader()},
|
||||
* {@link #getOddHeader()} and
|
||||
* {@link #getEvenHeader()}
|
||||
*/
|
||||
public Header getHeader() {
|
||||
// The default header is an odd header
|
||||
return getOddHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the odd footer. Used on all pages unless
|
||||
* other footers also present, when used on only
|
||||
* odd pages.
|
||||
*/
|
||||
public Footer getOddFooter() {
|
||||
return new XSSFOddFooter(getSheetTypeHeaderFooter());
|
||||
}
|
||||
/**
|
||||
* Returns the even footer. Not there by default, but
|
||||
* when set, used on even pages.
|
||||
*/
|
||||
public Footer getEvenFooter() {
|
||||
return new XSSFEvenFooter(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first page footer. Not there by
|
||||
* default, but when set, used on the first page.
|
||||
*/
|
||||
public Footer getFirstFooter() {
|
||||
return new XSSFFirstFooter(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
public Header getHeader() {
|
||||
return getOddHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the odd header. Used on all pages unless
|
||||
* other headers also present, when used on only
|
||||
* odd pages.
|
||||
*/
|
||||
public Header getOddHeader() {
|
||||
return new XSSFOddHeader(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the even header. Not there by default, but
|
||||
* when set, used on even pages.
|
||||
*/
|
||||
public Header getEvenHeader() {
|
||||
return new XSSFEvenHeader(getSheetTypeHeaderFooter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first page header. Not there by
|
||||
* default, but when set, used on the first page.
|
||||
*/
|
||||
public Header getFirstHeader() {
|
||||
return new XSSFFirstHeader(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
|
||||
public boolean getHorizontallyCenter() {
|
||||
return getSheetTypePrintOptions().getHorizontalCentered();
|
||||
}
|
||||
|
@ -281,10 +281,14 @@ public class TestXSSFSheet extends TestCase {
|
||||
|
||||
public void testGetFooter() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
XSSFSheet sheet = (XSSFSheet)workbook.createSheet("Sheet 1");
|
||||
assertNotNull(sheet.getFooter());
|
||||
sheet.getFooter().setCenter("test center footer");
|
||||
assertEquals("test center footer", sheet.getFooter().getCenter());
|
||||
|
||||
// Default is odd footer
|
||||
assertNotNull(sheet.getOddFooter());
|
||||
assertEquals("test center footer", sheet.getOddFooter().getCenter());
|
||||
}
|
||||
|
||||
public void testGetAllHeadersFooters() {
|
||||
@ -321,6 +325,9 @@ public class TestXSSFSheet extends TestCase {
|
||||
sheet.getOddHeader().setCenter("odd header center");
|
||||
assertEquals("odd header center", sheet.getOddHeader().getCenter());
|
||||
|
||||
// Defaults are odd
|
||||
assertEquals("odd footer left", sheet.getFooter().getLeft());
|
||||
assertEquals("odd header center", sheet.getHeader().getCenter());
|
||||
}
|
||||
|
||||
public void testGetSetColumnWidth() {
|
||||
|
Loading…
Reference in New Issue
Block a user