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();
|
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.
|
* @return The Document header.
|
||||||
*/
|
*/
|
||||||
Header getHeader();
|
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.
|
* @return The Document footer.
|
||||||
*/
|
*/
|
||||||
Footer getFooter();
|
Footer getFooter();
|
||||||
|
@ -32,7 +32,11 @@ public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
|
if(text == null) {
|
||||||
|
getHeaderFooter().unsetEvenFooter();
|
||||||
|
} else {
|
||||||
getHeaderFooter().setEvenFooter(text);
|
getHeaderFooter().setEvenFooter(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,11 @@ public class XSSFEvenHeader extends XSSFHeaderFooter implements Header{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
|
if(text == null) {
|
||||||
|
getHeaderFooter().unsetEvenHeader();
|
||||||
|
} else {
|
||||||
getHeaderFooter().setEvenHeader(text);
|
getHeaderFooter().setEvenHeader(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,10 @@ public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
|
if(text == null) {
|
||||||
|
getHeaderFooter().unsetFirstFooter();
|
||||||
|
} else {
|
||||||
getHeaderFooter().setFirstFooter(text);
|
getHeaderFooter().setFirstFooter(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,11 @@ public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
|
if(text == null) {
|
||||||
|
getHeaderFooter().unsetFirstHeader();
|
||||||
|
} else {
|
||||||
getHeaderFooter().setFirstHeader(text);
|
getHeaderFooter().setFirstHeader(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,10 @@ public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
|
if(text == null) {
|
||||||
|
getHeaderFooter().unsetOddFooter();
|
||||||
|
} else {
|
||||||
getHeaderFooter().setOddFooter(text);
|
getHeaderFooter().setOddFooter(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,10 @@ public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
|
if(text == null) {
|
||||||
|
getHeaderFooter().unsetOddHeader();
|
||||||
|
} else {
|
||||||
getHeaderFooter().setOddHeader(text);
|
getHeaderFooter().setOddHeader(text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,13 +381,6 @@ public class XSSFSheet implements Sheet {
|
|||||||
return getSheetTypePageSetUpPr().getFitToPage();
|
return getSheetTypePageSetUpPr().getFitToPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Footer getFooter() {
|
|
||||||
return getOddFooter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Footer getOddFooter() {
|
|
||||||
return new XSSFOddFooter(getSheetTypeHeaderFooter());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CTHeaderFooter getSheetTypeHeaderFooter() {
|
protected CTHeaderFooter getSheetTypeHeaderFooter() {
|
||||||
if (worksheet.getHeaderFooter() == null) {
|
if (worksheet.getHeaderFooter() == null) {
|
||||||
@ -396,31 +389,80 @@ public class XSSFSheet implements Sheet {
|
|||||||
return worksheet.getHeaderFooter();
|
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() {
|
public Footer getEvenFooter() {
|
||||||
return new XSSFEvenFooter(getSheetTypeHeaderFooter());
|
return new XSSFEvenFooter(getSheetTypeHeaderFooter());
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns the first page footer. Not there by
|
||||||
|
* default, but when set, used on the first page.
|
||||||
|
*/
|
||||||
public Footer getFirstFooter() {
|
public Footer getFirstFooter() {
|
||||||
return new XSSFFirstFooter(getSheetTypeHeaderFooter());
|
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() {
|
public Header getOddHeader() {
|
||||||
return new XSSFOddHeader(getSheetTypeHeaderFooter());
|
return new XSSFOddHeader(getSheetTypeHeaderFooter());
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns the even header. Not there by default, but
|
||||||
|
* when set, used on even pages.
|
||||||
|
*/
|
||||||
public Header getEvenHeader() {
|
public Header getEvenHeader() {
|
||||||
return new XSSFEvenHeader(getSheetTypeHeaderFooter()
|
return new XSSFEvenHeader(getSheetTypeHeaderFooter()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns the first page header. Not there by
|
||||||
|
* default, but when set, used on the first page.
|
||||||
|
*/
|
||||||
public Header getFirstHeader() {
|
public Header getFirstHeader() {
|
||||||
return new XSSFFirstHeader(getSheetTypeHeaderFooter());
|
return new XSSFFirstHeader(getSheetTypeHeaderFooter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean getHorizontallyCenter() {
|
public boolean getHorizontallyCenter() {
|
||||||
return getSheetTypePrintOptions().getHorizontalCentered();
|
return getSheetTypePrintOptions().getHorizontalCentered();
|
||||||
}
|
}
|
||||||
|
@ -281,10 +281,14 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetFooter() {
|
public void testGetFooter() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
XSSFSheet sheet = (XSSFSheet)workbook.createSheet("Sheet 1");
|
||||||
assertNotNull(sheet.getFooter());
|
assertNotNull(sheet.getFooter());
|
||||||
sheet.getFooter().setCenter("test center footer");
|
sheet.getFooter().setCenter("test center footer");
|
||||||
assertEquals("test center footer", sheet.getFooter().getCenter());
|
assertEquals("test center footer", sheet.getFooter().getCenter());
|
||||||
|
|
||||||
|
// Default is odd footer
|
||||||
|
assertNotNull(sheet.getOddFooter());
|
||||||
|
assertEquals("test center footer", sheet.getOddFooter().getCenter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetAllHeadersFooters() {
|
public void testGetAllHeadersFooters() {
|
||||||
@ -321,6 +325,9 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
sheet.getOddHeader().setCenter("odd header center");
|
sheet.getOddHeader().setCenter("odd header center");
|
||||||
assertEquals("odd header center", sheet.getOddHeader().getCenter());
|
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() {
|
public void testGetSetColumnWidth() {
|
||||||
|
Loading…
Reference in New Issue
Block a user