• 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

How to generate an MS Word Doc from Java Application ?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

Can anybody help me on how to generate an MS Word Doc using some Java API ?

My requirement is that I have to generate MS Word doc which will have some text, tables and some circles, squares, triangles to be drawn on text depends on some calculation logic. The text will come from screen or some other document.

I searched, on net and forum also and found some information related to Apache POI, but did not get if this will surely match with my requirement.
Also I have no knowledge about Apache POI and it seems very vast, so not getting from where to start ?


Any kind of help in this regard will be very helpful.

Thanking You !

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think JiG is the correct forum for this question, so I will move it over to the open source forum where usually such questions are discussed.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a starting point for the POI DOC API: https://coderanch.com/how-to/java/CreateWordDocument

The way to embed graphics would be to create images containing those graphics, and then adding those images to the document.

I think the HWPF API only lets you extract images, though, not create/add new ones (see HWPFDocument.getPicturesTable). You may have to resort to the XWPF API (which deals with the XML-format DOCX files) instead of the HWPF API (which handles the binary DOC files). The APIs are broadly similar, so you should be able to adapt the example code to XWPF.
 
pratibha patel
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf for your valuable reply

Ulf Dittmer wrote:Here's a starting point for the POI DOC API: https://coderanch.com/how-to/java/CreateWordDocument



I looked into the code and want to run in eclipse environment. But can you please let me know, what all supporting Jar or lib files are required in order to execute it without an error.

Thanking You !
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just download the latest Apache POI release build. I advise to try to infer form the jar file names which ones you may or may not need, so that you get an idea of how it all fits together. As long as you are getting exceptions, something is missing :-)
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may also try Aspose.Words for Java to create DOC files. This component is available with complete documentation and support. This component provides a rich set of features which can be easily incorporated in your applications without the need for any other software etc. Please see if it works for you.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic