poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Beardsley <markbrd...@tiscali.co.uk>
Subject Re: Help in XWPF POI code
Date Wed, 01 Dec 2010 16:20:38 GMT

Have not had the chance to play with any code yet but have taken a very quick
look at the javadoc for XWPFRun and it does define both a getText() and
setText() method. Therefore, it should be possible to check each character
run for the search term(s) and replace then if found. The only caveat to
this would be if the search term spanned two or more character runs -
imagine that the first part of the search term was in a different font for
example. Of course, this would complicate the issue but it should still be
possible to get around the problem by getting the text for the paragraph and
searching that for occurrences of the search term.

As before, will post again if (and when) I do get some code together. If you
have the opportunity to work on the problem, then this is the basic
processing;

Open the document - create an occurrence of XWPFDocument.
Call the getParagraphs() method on the SXPFDocument and this will return a
List of XWPFParagraph instances.
Step through the List one element at a time and for each XWPFParagraph call
the getRuns() method.
This will return another List, this time containing instances of the XWPFRun
class.
Step through this second List and for each run, call the getText() method to
recover a String that encspaulates the runs text. Search through this for
the search term using core Java code and, if the term is found, replace it
and then call the runs setText() method to update it's contents.

I think that will work but only testing will tell of course.

Yours

Mark B
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Help-in-XWPF-POI-code-tp3287261p3287927.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Mime
View raw message