You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2012/03/31 00:32:32 UTC
DO NOT REPLY [Bug 53009] New: Problem creating header and footer
https://issues.apache.org/bugzilla/show_bug.cgi?id=53009
Bug #: 53009
Summary: Problem creating header and footer
Product: POI
Version: 3.8-dev
Platform: PC
Status: NEW
Severity: normal
Priority: P2
Component: XWPF
AssignedTo: dev@poi.apache.org
ReportedBy: rngo@tk20.com
Classification: Unclassified
Created attachment 28520
--> https://issues.apache.org/bugzilla/attachment.cgi?id=28520
java program to generate docx file
unable to create a simple header and footer text if creating a new document.
Using a simple test program, the header and footer xml prints the xml content
twice. I am also including the patch but I am not sure what side effect it has
by commenting part of the code out.
Let me know! thanks!
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 53009] Problem creating header and footer
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53009
--- Comment #2 from Mike McCullough <mi...@gmail.com> ---
I have noticed the same problems as well, and can provide some additional
information where the problem likely occurs. Within XWPFHeaderFooterPolicy, the
code for creating of a footer looks like:
public XWPFFooter createFooter(Enum type, XWPFParagraph[] pars) throws
IOException {
XWPFRelation relation = XWPFRelation.FOOTER;
String pStyle = "Footer";
int i = getRelationIndex(relation);
FtrDocument ftrDoc = FtrDocument.Factory.newInstance();
XWPFFooter wrapper = (XWPFFooter)doc.createRelationship(relation,
XWPFFactory.getInstance(), i);
CTHdrFtr ftr = buildFtr(type, pStyle, wrapper, pars);
wrapper.setHeaderFooter(ftr);
OutputStream outputStream = wrapper.getPackagePart().getOutputStream();
ftrDoc.setFtr(ftr);
XmlOptions xmlOptions = commit(wrapper);
assignFooter(wrapper, type);
ftrDoc.save(outputStream, xmlOptions);
outputStream.close();
return wrapper;
}
The important line of code is:
ftrDoc.save(outputStream, xmlOptions);
which provides the first line of XML to be saved (e.g., saved in footer1.xml).
The footer will additionally be saved with the final write() function within
the POIXMLDocument. Since a header or footer is considered to be a
org.apache.poi.openxml4j.opc.PackagePart, the write() function will iterate
through all package parts and save them as well.
The onSave(Set<PackagePart> alreadySaved) function in POIXMLDocumentPart calls
commit() in the first line of the function. Within the overriden implementation
of commit() in the XWPFFooter class, the penultimate line has:
super._getHdrFtr().save(out, xmlOptions);
which will cause the second line of the XML footer information to be written as
well.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 53009] Problem creating header and footer
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53009
benoit.duffez@gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |benoit.duffez@gmail.com
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 53009] Problem creating header and footer
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53009
--- Comment #4 from benoit.duffez@gmail.com ---
Alex' workaround works fine, however the same must be done for the header by
removing the appropriate hdrDoc.save()
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
DO NOT REPLY [Bug 53009] Problem creating header and footer
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53009
--- Comment #1 from Richard Ngo <rn...@tk20.com> 2012-03-30 22:33:52 UTC ---
Created attachment 28521
--> https://issues.apache.org/bugzilla/attachment.cgi?id=28521
commented 2nd write to the xml
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 53009] Problem creating header and footer
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53009
Benoit D <be...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|3.8-dev |3.9
Severity|normal |major
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 53009] Problem creating header and footer
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53009
--- Comment #3 from Alex K <ak...@gmail.com> ---
I ended up creating a new header footer policy class (that extends the default)
and doesn't call ftrDoc.save() . That approach works, but it would be nice if
the default worked out of the box and didn't require a workaround.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org