• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Append a Word .doc after another one using POI HWPF

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody!

I think that the topic title says almost all about it, but I'll try to be more specific: I have a tomcat servlet which prints out a bunch of .doc files (which are created using JasperReports if this is important) and I need to take those files and put them all in a single file.

Googling around I found this "POI" project which seems to enable Java programmers to be able to manipulate Microsoft Office files (and so also .doc file) using their API, which I downloaded the last version. But I'm not really sure about how actually do this.

Here is what I was thinking to do, from a very high-level point of view:
- create an empty HWPF document
- read the first .doc file into another HWPF document
- copy the content from the last created document to the empty one
- read the second .doc file
- and so on...

Can any of you please help me understand how to implement this? Thank you very much in advance.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Maybe these previous discussion on similar topics will get you started:

https://coderanch.com/t/440303/Other-Open-Source-Projects/Mearging-two-word-documents-using

https://coderanch.com/t/424192/Other-Open-Source-Projects/HWPF-Mail-Merging
 
Matteo Tassinari
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Basically my conclusion is that you cannot 'really append' one word document to another using POI.
The best you could do is extract the text and text format and append it to another document. This will work only in case of really simple work documents.



Uhm, that doesn't sound good for me. The documents I need to merge together are all full of tables, images, and also uses different styles.

I was hoping to find a way to do this in Java 'cause if there is one, then the company for which I work wouldn't need to completely rewrite the reporting utility of our software (which is based on tomcat and Java servlets).
 
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
Another approach might be to use OpenOffice in server mode. It has a Java API that could be used to open the first file, and then insert all other files at the end successively.
 
Matteo Tassinari
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That could be an idea, but since this "merging" solution will need to get installed on our customers computers (because it would obviously be shipped in bundle with our software, a web-based AMP application), I do not think they'd accept to have an openoffice server running on their computers. And this would also require major modifications of our software, that would not be really cost-effective
 
reply
    Bookmark Topic Watch Topic
  • New Topic