File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Creating word documents file from templates. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Creating word documents file from templates." Watch "Creating word documents file from templates." New topic
Author

Creating word documents file from templates.

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205

Hi, I have req. to create word documents files using templates. Please let me know which API or third party tool to use.
Thanks in advance.

Rahul
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Does it have to be Word? RTF would be so much easier, since it's all text that you can work with using search/replace. If you really need Word, the Apache POI library may be the way to go: http://faq.javaranch.com/java/CreateWordDocument
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Apache POI: http://poi.apache.org/
OpenOffice UNO: http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OpenOffice.org_Developers_Guide


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205

ya, I just have concern regarding Apachee POI..wheneter we can generate reports from template in POI? I did not find any example hence writing.

And how's experience with OpenOffice?
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
I never used the Open Office API, and POI only related to XLS documents. In that case there's a Workbook constructor that takes a 'template workbook' as parameter ... I think that's pretty simple. So maybe for other types of documents the handling could be similar.
-> http://stackoverflow.com/questions/714172/poi-using-excel-templates
-> http://www.coderanch.com/t/436727/open-source/create-MS-Word-Doc-HWPF
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205
Hi, I think I should go with Apache POI...but just want to check I have template and want to create word document only.
In template I have something $date$ where I have to put current date. Any Idea how to proceed with it.

I wrote a sample code, but it's not working



pages.dot template contains $date$, but in resultant text it's not filling the expected data.

and another thing is that In Template only I have table, I have to put the dynamicly generated data in front of Main System and File Name which I will get it from db.

so, below format is in Template file:

--------------------------------------------------------------
Main System :
--------------------------------------------------------------
File Name :
---------------------------------------------------------------

Thanks in advance as usual.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I'm not a POI user but does the s.replaceText("date", "Hi Hello"); method truly reference the $date$ variable?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
jQuery in Action, 2nd edition
 
subject: Creating word documents file from templates.
 
Similar Threads
How to create MS Word Doc using HWPF POI
How to get a word document file in a JText Area?
Printing word documents from Servlet
OOo/SO file formats
Java IDE's