Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating word documents file from templates.

 
Rahul Ba
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apache POI: http://poi.apache.org/
OpenOffice UNO: http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OpenOffice.org_Developers_Guide
 
Rahul Ba
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not a POI user but does the s.replaceText("date", "Hi Hello"); method truly reference the $date$ variable?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic