• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding Header/Footer to Word Document, created using HWPF/XWPF.  RSS feed

 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have written code to create a word document using Apache XWPF. I need to add a header and footer to this word doc.
Following is the code:



================================================================================

When I run the above piece of code, I am getting the following runtime exception:

Caught an: java.lang.NullPointerException
Message: null
Stacktrace follows:.....
java.lang.NullPointerException
at org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy.<init>(XWPFHeaderFooterPolicy.java:106)
at org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy.<init>(XWPFHeaderFooterPolicy.java:92)
at HeaderFooterExample.createDocument(HeaderFooterExample.java:56)
at HeaderFooterExample.main(HeaderFooterExample.java:199)

=============================================================================

I am not sure what is wrong with the above code.
Any help on how to create a word document with header/footer using HWPF/XWPF will be appreciated.

Thanks..





 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the stacktrace, I would assume the XWPFDocument is not in a valid state for ceating an XWPFHeaderFooterPolicy.
Maybe there's more information on pre-conditions in the POI API or user documentation?
 
asif aftab
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced this issue and the solution is We have to use 3.10 final poi jar. 3.9 having this problem. Please remove jars of previous version and add jars of 3.10 final version in which this bug is fixed. jars requires are 1. poi-3.10-FINAL.jar 2. poi-ooxml-3.10-FINAL.jar 3. poi-ooxml-schemas-3.10-FINAL.jar Easily available in net.

jar download page



The above code is working perfectly, please use 3.10 wars those I mentioned above.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!