poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angelo zerr <angelo.z...@gmail.com>
Subject Re: Problem replacing texts
Date Tue, 20 Oct 2015 18:39:09 GMT
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 <dominik.stadler@gmx.at>:

> 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" <edilista@intersite.com.br>:
>
> > 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: user-unsubscribe@poi.apache.org
> > For additional commands, e-mail: user-help@poi.apache.org
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message