poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gillio_simi...@ieci.es
Subject Re: POI - HWPFDocument
Date Thu, 11 Dec 2008 09:13:43 GMT
Hi Anthony.

I tested InsertText java class wuth the word file you have sent me 
recently but It still doesn't work.....I got this error:

Caught an: java.lang.IllegalArgumentException
Message: The end (595) must not be before the start (662)
StackTrace follows:
java.lang.IllegalArgumentException: The end (595) must not be before the 
start (662)
        at org.apache.poi.hwpf.usermodel.Range.sanityCheckStartEnd(
Range.java:247)
        at org.apache.poi.hwpf.usermodel.Range.<init>(Range.java:181)
        at org.apache.poi.hwpf.usermodel.Paragraph.<init>(
Paragraph.java:103)
        at org.apache.poi.hwpf.usermodel.Range.getParagraph(Range.java:830
)
        at wordtest.InsertText.processFile(InsertText.java:136)
        at wordtest.InsertText.main(InsertText.java:288)

I tested once again with my word file that I attach with this email, but 
still the same: word could open the "Copy.doc" file.







Anthony Andrews <pythonaddict@yahoo.com>
11/12/2008 09:43
Por favor, responda a "POI Users List"
 
        Para:   POI Users List <user@poi.apache.org>
        cc: 
        Asunto: Re: POI - HWPFDocument


Yes of course I can. Here is the link;

http://rapidshare.com/files/172312114/Test.doc.html

Would you test this file against 'my' code again and, if possible and I do 
understand if your employer refuses to allow this, let me have a copy of 
your file please - the one that failed in your tests - so that I can have 
a look for possible reasons?

--- On Thu, 12/11/08, gillio_simione@ieci.es <gillio_simione@ieci.es> 
wrote:
From: gillio_simione@ieci.es <gillio_simione@ieci.es>
Subject: Re: POI - HWPFDocument
To: "POI Users List" <user@poi.apache.org>
Date: Thursday, December 11, 2008, 12:33 AM

Sorry Anthony but I didn´t recive the attach...

Could you upload it to RapidShare like You did for the Word.war file?

Thanks in advance..

Gilio Simione.





Anthony Andrews <pythonaddict@yahoo.com>
10/12/2008 20:06
Por favor, responda a "POI Users List"
 
        Para:   POI Users List <user@poi.apache.org>
        cc: 
        Asunto: Re: POI - HWPFDocument



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, gillio_simione@ieci.es <gillio_simione@ieci.es> 
wrote:
From: gillio_simione@ieci.es <gillio_simione@ieci.es>
Subject: Re: POI - HWPFDocument
To: "POI Users List" <user@poi.apache.org>
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 <pythonaddict@yahoo.com> 
10/12/2008 08:42 
Por favor, responda a "POI Users List" 
 
        Para:        POI Users List <user@poi.apache.org> 
        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, gillio_simione@ieci.es <gillio_simione@ieci.es> 
wrote: 
From: gillio_simione@ieci.es <gillio_simione@ieci.es>
Subject: Re: POI - HWPFDocument
To: "POI Users List" <user@poi.apache.org>
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 <pythonaddict@yahoo.com>
09/12/2008 16:09
Por favor, responda a "POI Users List"

       Para:   POI Users List <user@poi.apache.org>
       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, gillio_simione@ieci.es <gillio_simione@ieci.es> 
wrote:
From: gillio_simione@ieci.es
<gillio_simione@ieci.es>
Subject: Re: POI - HWPFDocument
To: "POI Users List" <user@poi.apache.org>
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 <pythonaddict@yahoo.com>
08/12/2008 08:53
Por favor, responda a "POI Users List"

       Para:   user@poi.apache.org
       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 <pythonaddict@yahoo.com> wrote:
From: Anthony Andrews <pythonaddict@yahoo.com>
Subject: Re: POI - HWPFDocument
To: "POI Users List" <user@poi.apache.org>
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, gillio_simione@ieci.es <gillio_simione@ieci.es> 
wrote:
From: gillio_simione@ieci.es <gillio_simione@ieci.es>
Subject: POI - HWPFDocument
To: user@poi.apache.org
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:
user-unsubscribe@poi.apache.org
For additional commands, e-mail:
user-help@poi.apache.org






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



 
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.

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