• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..





 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic