I have attached a copy of the test file I used - run the code against this and 
see what happens. It may be that the file you are using contains something I 
had not anticipated.

If the code runs successfully against my file but still fails when run against 
yours, would it be possible for you to let me have a copy of your test file 
please so that I can dig around a bit?

--- On Wed, 12/10/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
From: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Subject: Re: POI - HWPFDocument
To: "POI Users List" <[email protected]>
Date: Wednesday, December 10, 2008, 3:15 AM



Hi Anthony.



Thanks again for help...



I downloaded the archive and tested
InsertText
java class, but I got an error when I tried to opened the file that It
generets at the end ("Copy.doc"); here the error message:

The Test.doc file contains only the
$PH1 parameter.





Seems the word document is corrupted.

Have you any idea?












Anthony Andrews <[EMAIL PROTECTED]>
10/12/2008 08:42

Por favor, responda a "POI Users
List"
        

        Para:
       POI Users List <[email protected]>

        cc:
       

        Asunto:
       Re: POI - HWPFDocument








Sorry about that, will try again. Just to make
sure, I have zipped the files into an archive and uploaded it to Rapidshare.



Assuming the attachments do not show again, just follow this link;



http://rapidshare.com/files/171985332/Word.rar.html



take the free download option and you should receive both source code files.
Of course, you will need to unzip them this time.



There is one good thing to come out of this, I remembered that I have left
a line of code in from testing. If you look into the processFile() method
of the InsertText class you should see this line near to the end of the
try block;



fileOutputStream = new FileOutputStream(new File("C:\\Temp\\Copy.doc"));



I hard coded the name of the file for testing purposes and you may wish
to change this. You can re-save the file using it's existing filename or
simply create a new one - passing a third parameter to the constructor
could be one solution.



--- On Tue, 12/9/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:

From: [EMAIL PROTECTED] <[EMAIL PROTECTED]>

Subject: Re: POI - HWPFDocument

To: "POI Users List" <[email protected]>

Date: Tuesday, December 9, 2008, 7:25 AM



Hi Anthony..



I didn´t recive the attach files..



Could you send me them once again please?



Thanks a lot.













Anthony Andrews <[EMAIL PROTECTED]>

09/12/2008 16:09

Por favor, responda a "POI Users List"

 

        Para:   POI Users List <[email protected]>

        cc: 

        Asunto: Re: POI - HWPFDocument







Course I can and have attached it to this email.



There are a

 couple of things you will need to do. Firstly, remove the 

package declaration from the top of both class files. Secondly, have a


look first at the InsertText classes main method because that shows you


the technique I chose to use - pass the name of the file and a HashMap


containing key/value pairs where the placeholder is the key and the text


you want to substitute the value. At present, there is no support for 

saving the file under a different name but that will be easy for you to


add.



I must add that the code has one limit - it will insert text but ignores


any treatments applied - font, size, colour, etc - defaulting to the 

'Normal' style. At the moment, I am not sure how to overcome this but

will 

continue to dig around if it proves to be a problem for you, just let me


know.



--- On Tue, 12/9/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]>


wrote:

From: [EMAIL PROTECTED]

 <[EMAIL PROTECTED]>

Subject: Re: POI - HWPFDocument

To: "POI Users List" <[email protected]>

Date: Tuesday, December 9, 2008, 12:49 AM



Thanks everybody for help.



Anthony I think that the code you wrote is what I need and looking for
few 



days.



Could you post the code, please?



Thank you very much to all once again...



Gilio Simione











Anthony Andrews <[EMAIL PROTECTED]>

08/12/2008 08:53

Por favor, responda a "POI Users List"

 

        Para:   [email protected]

        cc: 

        Asunto: Re: POI - HWPFDocument





Yestreday, the ground was too frozen for us to plant trees so I spent the


day in the workshop

 (un-heated I must add). In between sharpening axes, 

and billhooks, replacing spade handles and the like I had the chance to


spend time at my desk playing around with some code.



Anyway, I think I may have

 sorted out the problem for you. The code I have 



written will search through a document one paragraph at a time and replace




search strings with text. It assumes a few things;



* The search and replacement text will be contained in a HashMap - each


key/value pair being a search term and it's associated replacement text.

* That each search term can appear zero, one or more times in each 

paragraph in any order.

* That the document may contain text, pictures, tables, etc.

* That tables should also be serached and updated if necessary.

* That the serach term and replacement text can be aggrefated into that


data structure - the HashMap. If not, it should be trivial task to alter


the logic.



If you

 want the code, let me know. It is still a little untidy and I would 

lke to create at least one supporting class but that is not strictly 

necessary. I will be working away freom the office today so

 forgive me 

please if I do not reply immediately.



--- On Fri, 12/5/08, Anthony Andrews <[EMAIL PROTECTED]> wrote:

From: Anthony Andrews <[EMAIL PROTECTED]>

Subject: Re: POI - HWPFDocument

To: "POI Users List" <[email protected]>

Date: Friday, December 5, 2008, 5:09 AM



Have a look at the Range class and you will see a method called 

replaceText(). This method can be used to replace one piece of text - 

called the placeholder - with another - called the replacement text much


in the manner of a mail merge I guess. If you look closely at the javadoc,




Paragraph is a subclass of Range so the method should be available on your




object 'p' meaning the changes you will have to make are

 (hopefully)

very 

simple.



I am far from being an expert so I do not know how you can use it to 

search through a document to replace numerous occurrences of a placeholder

 



but suspect there is a way because it is possible to define the offset
- 

the point within the document at which the method begins searching for
the 



text to replace.



--- On Fri, 12/5/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]>


wrote:

From: [EMAIL PROTECTED] <[EMAIL PROTECTED]>

Subject: POI - HWPFDocument

To: [email protected]

Date: Friday, December 5, 2008, 12:52 AM







Hallo everyboby.







I have benn looking for the last days

in internet trying to find a solution for my problem, and I found nothing

that could help me...so I am asking you help... 







The problem:







I store in oracle table field (BLOB)

a word document.This document is a template

 whose content is text and also

few fields that  I'm trying to fill up at runtime using HWPFDocument...but

I don't find the way.



What I want to do is at field with

 name

"name" put e.g. "Myname", to address

put "MyAddress" and so on.....







Here few code lines and what it prints







Range r = wordDocument.getRange();



 

for (int x = 0; x < r.numSections(); x++){



 

  Section s = r.getSection(x);



 

  for (int y = 0; y < s.numParagraphs(); y++){



 

          Paragraph p = s.getParagraph(y);



 

          for (int z = 0; z <

p.numCharacterRuns(); z++){



 

 

  CharacterRun run = p.getCharacterRun(z);



 

 

  //character run text



 

 

  String text = run.text();



 

 

 

 System.out.println(text);



 

          }



 

  }



      }











"name"







John Smith



















"address"







99 North Road



















"postCode"







X1 2YZ









 







"city"







London











































"date"







Tuesday, 8 August 2006







































Dear 







"name"







John Smith











.......







Hope my english is understandable...







Thanks in advance.







Gilio Simione







P.S.







Here is the template stores in the database.















Este mensaje, y en su caso, cualquier fichero anexo al mismo,

 puede

contener informacion confidencial, siendo para uso exclusivo del 

destinatario, quedando prohibida su divulgacion copia o  distribucion
a 

terceros sin la autorizacion expresa del remitente. Si Vd. ha recibido


este mensaje erroneamente, se ruega lo  notifique al remitente y 

proceda a su borrado.

Gracias

 por su colaboracion.



This message (including any attachments) may contain confidential 

information. It is intended for use by the recipient only. Any 

dissemination, copying or distribution to third parties without the 

express consent of the sender is strictly prohibited. If you have 

received this message in error, please delete it immediately and 

notify the sender. 

Thank you for your collaboration.

---------------------------------------------------------------------

To unsubscribe, e-mail:

 [EMAIL PROTECTED]

For additional commands, e-mail:

 [EMAIL PROTECTED]





 





 

Este mensaje, y en su caso, cualquier fichero anexo al mismo, puede

contener informacion confidencial, siendo para uso exclusivo del 

destinatario, quedando prohibida su divulgacion copia o  distribucion
a 

terceros sin la autorizacion expresa del remitente. Si Vd. ha recibido


este mensaje

 erroneamente, se ruega lo  notifique al remitente y 

proceda a su borrado.

Gracias por su colaboracion.



This message (including any attachments) may contain confidential 

information. It is intended for use by the recipient only. Any 

dissemination, copying or distribution to third parties without the 

express consent of the sender is strictly prohibited. If you have 

received this message in error, please delete it immediately and 

notify the sender. 

Thank you for your collaboration.

---------------------------------------------------------------------

To unsubscribe, e-mail: [EMAIL PROTECTED]

For additional commands, e-mail: [EMAIL PROTECTED]

Este mensaje, y en su caso, cualquier fichero anexo al mismo, puede

contener informacion confidencial, siendo para uso exclusivo del 

destinatario, quedando prohibida su divulgacion copia o  distribucion
a 

terceros sin la autorizacion

 expresa del remitente. Si Vd. ha recibido 

este mensaje erroneamente, se ruega lo  notifique al remitente y 

proceda a su borrado.

Gracias por su colaboracion.



This message (including any attachments) may contain confidential 

information. It is intended for use by the recipient only. Any 

dissemination, copying or distribution to third parties without the 

express consent of the sender is strictly prohibited. If you have 

received this message in error, please delete it immediately and 

notify the sender. 

Thank you for your collaboration.

---------------------------------------------------------------------

To unsubscribe, e-mail: [EMAIL PROTECTED]

For additional commands, e-mail: [EMAIL PROTECTED]

Este mensaje, y en su caso, cualquier fichero anexo al mismo, puede
contener informacion confidencial, siendo para uso exclusivo del 
destinatario, quedando prohibida su divulgacion copia o  distribucion a 
terceros sin la autorizacion expresa del remitente. Si Vd. ha recibido 
este mensaje erroneamente, se ruega lo  notifique al remitente y 
proceda a su borrado.
Gracias por su colaboracion.

This message (including any attachments) may contain confidential 
information. It is intended for use by the recipient only. Any 
dissemination, copying or distribution to third parties without the 
express consent of the sender is strictly prohibited. If you have 
received this message in error, please delete it immediately and 
notify the sender. 
Thank you for your collaboration.



      
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to