This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Append a Word .doc after another one using POI HWPF

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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: 43011
76
  • Mark post as helpful
  • send pies
  • 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
  • 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: 43011
76
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Let's get him boys! We'll make him read this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!