mirror of https://github.com/apache/poi.git
Added overloaded method to support multiple paragraphs in footer/header
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@947686 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c6a5ff361c
commit
38c8b8eae1
|
@ -174,6 +174,8 @@ public class XWPFHeaderFooterPolicy {
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public XWPFFooter createFooter(Enum type) throws IOException {
|
public XWPFFooter createFooter(Enum type) throws IOException {
|
||||||
return createFooter(type, null);
|
return createFooter(type, null);
|
||||||
|
@ -214,14 +216,16 @@ public class XWPFHeaderFooterPolicy {
|
||||||
|
|
||||||
|
|
||||||
private CTHdrFtr buildFtr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
|
private CTHdrFtr buildFtr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
|
||||||
CTHdrFtr ftr = buildHdrFtr(pStyle, pars);
|
//CTHdrFtr ftr = buildHdrFtr(pStyle, pars); // MB 24 May 2010
|
||||||
|
CTHdrFtr ftr = buildHdrFtr(pStyle, pars, wrapper); // MB 24 May 2010
|
||||||
setFooterReference(type, wrapper);
|
setFooterReference(type, wrapper);
|
||||||
return ftr;
|
return ftr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private CTHdrFtr buildHdr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
|
private CTHdrFtr buildHdr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
|
||||||
CTHdrFtr hdr = buildHdrFtr(pStyle, pars);
|
//CTHdrFtr hdr = buildHdrFtr(pStyle, pars); // MB 24 May 2010
|
||||||
|
CTHdrFtr hdr = buildHdrFtr(pStyle, pars, wrapper); // MB 24 May 2010
|
||||||
setHeaderReference(type, wrapper);
|
setHeaderReference(type, wrapper);
|
||||||
return hdr;
|
return hdr;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +235,40 @@ public class XWPFHeaderFooterPolicy {
|
||||||
if (paragraphs != null) {
|
if (paragraphs != null) {
|
||||||
for (int i = 0 ; i < paragraphs.length ; i++) {
|
for (int i = 0 ; i < paragraphs.length ; i++) {
|
||||||
CTP p = ftr.addNewP();
|
CTP p = ftr.addNewP();
|
||||||
ftr.setPArray(0, paragraphs[i].getCTP());
|
//ftr.setPArray(0, paragraphs[i].getCTP()); // MB 23 May 2010
|
||||||
|
ftr.setPArray(i, paragraphs[i].getCTP()); // MB 23 May 2010
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CTP p = ftr.addNewP();
|
||||||
|
byte[] rsidr = doc.getDocument().getBody().getPArray()[0].getRsidR();
|
||||||
|
byte[] rsidrdefault = doc.getDocument().getBody().getPArray()[0].getRsidRDefault();
|
||||||
|
p.setRsidP(rsidr);
|
||||||
|
p.setRsidRDefault(rsidrdefault);
|
||||||
|
CTPPr pPr = p.addNewPPr();
|
||||||
|
pPr.addNewPStyle().setVal(pStyle);
|
||||||
|
}
|
||||||
|
return ftr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MB 24 May 2010. Created this overloaded buildHdrFtr() method because testing demonstrated
|
||||||
|
* that the XWPFFooter or XWPFHeader object returned by calls to the createHeader(int, XWPFParagraph[])
|
||||||
|
* and createFooter(int, XWPFParagraph[]) methods or the getXXXXXHeader/Footer methods where
|
||||||
|
* headers or footers had been added to a document since it had been created/opened, returned
|
||||||
|
* an object that contained no XWPFParagraph objects even if the header/footer itself did contain
|
||||||
|
* text. The reason was that this line of code; CTHdrFtr ftr = CTHdrFtr.Factory.newInstance();
|
||||||
|
* created a brand new instance of the CTHDRFtr class which was then populated with data when
|
||||||
|
* it should have recovered the CTHdrFtr object encapsulated within the XWPFHeaderFooter object
|
||||||
|
* that had previoulsy been instantiated in the createHeader(int, XWPFParagraph[]) or
|
||||||
|
* createFooter(int, XWPFParagraph[]) methods.
|
||||||
|
*/
|
||||||
|
private CTHdrFtr buildHdrFtr(String pStyle, XWPFParagraph[] paragraphs, XWPFHeaderFooter wrapper) {
|
||||||
|
CTHdrFtr ftr = wrapper._getHdrFtr();
|
||||||
|
if (paragraphs != null) {
|
||||||
|
for (int i = 0 ; i < paragraphs.length ; i++) {
|
||||||
|
CTP p = ftr.addNewP();
|
||||||
|
ftr.setPArray(i, paragraphs[i].getCTP());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue