Hi Angelo,

I tried xdocreport.
I got to replace texts but the resulting file is not the same as the source. The fonts becomes bigger and the color of words that were black now become blue. I copied the sample code from https://github.com/opensagres/xdocreport/wiki/Overview and just changed the source and
destination file names to my files.

On 20-10-2015 15:39, Angelo zerr wrote:
Hi Edilmar,

You could try too https://github.com/opensagres/xdocreport

You use mergefield with Velocity/Freemarker syntax in your docx and you can
manage condition, loop, etc

XDocReport provides too converter like docx->pdf based on POI+iText.

Hope it will help you.

Regard's Angelo

2015-10-20 17:45 GMT+02:00 Dominik Stadler <[email protected]>:

Hi, I have a similar project at https://github.com/centic9/poi-mail-merge,
it allows to do "mail merges", i.e. replace tags in a template document
multiple times. Only it is based on XWPF not HWPF, so it will only be
useful to you if you can switch to the newer docx-format.

Dominik
Am 20.10.2015 16:13 schrieb "Edilmar LISTAS" <[email protected]>:

Hi,

I use POI for simple .doc/.xls handling.
But now I have a little more complex .doc file to handle,
and POI has done something wrong (or my code).
I searched in the internet and POI docs but didn't find the solution.

The template file has a table with many cells like a client record,
with name, address, phone, etc. I have tags like <NAME>, etc
that I would like to change by database values.

The result file after POI processing to replace tags is misconfigured,
the table is lost and all the text values become all together.

I used this code to replace:

   public void replaceTags(String origFile, String destFile, Map<String,
String> properties) throws IOException {
     POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream(origFile));
     HWPFDocument doc = new HWPFDocument(fs);
     Range range = doc.getRange();
     Set<Entry<String, String>> set = properties.entrySet();
     Iterator<Entry<String, String>> it = set.iterator();
     while (it.hasNext()) {
       Entry<String, String> entry = it.next();
       range.replaceText(entry.getKey(), entry.getValue());
     }
     OutputStream output = new FileOutputStream(destFile);
     doc.write(output);
   }

This is the call to replaceTags:

       Map<String, String> properties = new HashMap<>();
       properties.put("<NAME>", "INTERSITE INFORMÁTICA");
       new

TemplateWord().replaceTags("/home/ed/orig.doc","/home/ed/dest.doc",properties);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]






---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to