Very much the same as you, Java 1.6,
poi-3.2-FINAL-20081019.jar/poi-scratchpad-3.2-FINAL-20081019.jar and either
Word 2000 or 2003 depending on the machine I am using at the time.

I did see some corruption of the final file - at least I think I did. Word
was quite happy and able to open the files the code generated but could not
save them again. This problem emerged whether or not I modified the file
after opening it in Word. OpenOffice did not have any qualms about
opening/modifying/saving the Word file modified by the search/Replace code
interestingly. Also after OpenoOffice had resaved the file, Word was happy
again.

Looking at the two files - the unmodified Word generated version and that
following the search and replace operation - there are differences. Sadly, I
am not knowledgable enough to determine whether or not they matter; it may
be that you will have to raise this as a bug if the problem persists.

Are you restricted to using HWPF? Can you install and use OpenOffice? It -
OpenOffice - does have an API that youu can access through Java code. It is
complex because Sun targetted the API at users of a variety of laguages but
the flip side of this is it's richness. I already have search and replace
code written that utilises this API and will be quite happy to let you have
it if you want. You do need to be aware that using OpenOffice inthis way
does have limitations - OpenOffice cannot be used as a document server so to
speak and it is quite slow, at least initially becuase you are interacting
with an instance of the application.

If OpenOffice so too much then have a look at AbiWord. It has a command line
interface called AbiCommand - which may be limited to Linux platforms but I
am not sure of this. It supports search and replace operations from the
command line and is pretty good at what it does. I have used it for file
conversions in the past - converting Word to rtf for example from the
command line. Have a look here;

http://www.abisource.com/

and here

http://www.abisource.com/wiki/AbiCommand

also, unlike OpenOffice, it can be used a document server; i.e. installed on
a remote machine and accessed by many users to accomplish different tasks.


bfavro-2 wrote:
> 
> 
> 
> Can anyone offer help on modifying Word 97-2003 documents in HWPF using
> POI 3.2? 
> 
> 
> 
> I am able to use insertBefore(text) and insertAfter(text) without any
> issues but my requirement is to change/replace tokens in the Word file
> with dynamic text much like the unit tests, e.g. ${organization} with
> "Apache Software Foundation" 
> 
> 
> 
> When I do this with Range.replaceText("${organization}", "Apache Software
> Foundation") the doc file keeps getting corrupted.  In viewing the file in
> a text editor I can see the replacement text but it is not compressed like
> the rest of the file. 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Modify-Word-document-tp23220457p23290978.html
Sent from the POI - User mailing list archive at Nabble.com.


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

Reply via email to