poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samirrolemberg <samirrolemb...@hotmail.com>
Subject Replacing text using HWPFDocument with POI 3.8 beta 4
Date Fri, 09 Sep 2011 17:44:27 GMT
Hello again.

I am using version 3.8 beta 4 Apache POI file to manipulate a template that
will serve as a report output some data.

In this case the Office file format is "doc" and I'm using HWPFDocument to
accomplish the task.

In the model, I have the following structure:

Header: This contains an image (company logo), the number of pages, the
header itself and a text to be printed on all pages generated by the report.

"Body", where contains a table with two columns and that are populated

Footnote: That is similar to the header, but contains information to be
populated dynamically. And links to the e-mail and website.

Using this:

	public void _replaceWord(InputStream filePath, Map&lt;String, String&gt;
map, String outputFileName) throws Exception{  

        HWPFDocument word = new HWPFDocument(new POIFSFileSystem(filePath));
        Range range = word.getRange();  //to replace the content in the cols
of the tables in the "body".
        range.replaceText("#n_v_left#", map.get("#n_v_left#"));
        range.replaceText("#n_v_right#", map.get("#n_v_right#"));

        HeaderStories hs = new HeaderStories(word);

        Range hsRange = hs.getRange();//to replace the content in header and
        hsRange.replaceText("#day#", map.get("#day#"));
        hsRange.replaceText("#mon#", map.get("#mon#"));
        hsRange.replaceText("#yea#", map.get("#yea#"));
        hsRange.replaceText("#n_1#", map.get("#n_1#"));
        hsRange.replaceText("#n_2#", map.get("#n_2#"));
        hsRange.replaceText("#serial#", map.get("#serial#"));
        OutputStream output = new FileOutputStream(outputFileName+".doc");  

All went well. The API replaces the tags correctly, but it became clear the
footer links and automatically place an image object at the bottom.

as in the image:
(Image is the original model that contains sensitive data, so the

I removed the images and ran the application again, but the same problem

Then I tried to return to a stable version of the API (3.7) (using the same
methods of replacement) but when I try to save a file, the file created is
generated as an invalid and corrupted.

And now I do not know what to do! anyone else has had this "problem"? 

View this message in context: http://apache-poi.1045710.n5.nabble.com/Replacing-text-using-HWPFDocument-with-POI-3-8-beta-4-tp4787192p4787192.html
Sent from the POI - Dev mailing list archive at Nabble.com.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org

View raw message