Satya Dev Lankepally wrote:
> i am doing search and replace kind of work by using POI > HWPF. I am getting
> text properly, but I am not getting format [bold, italic and underline]. How
> can I get format for the text?
> 
> Please help me ...

Hi,

to retrieve the formatting you can use the Range class
(org.apache.poi.hwpf.usermodel.Range). It works like this:

  HWPFDocument doc = new HWPFDocument(new FileInputStream(file));
  Range range = new Range(startIndex, endIndex, doc);
  CharacterRun cr = range.getCharacterRun(0);
  System.out.println("isBold=" + cr.isBold());

(startIndex and endIndex being the text interval you wish to look at. A
Range may cover several CharacterRuns, the code above just retrieves the
first one.)

The formatting information in a Word file is spread around in style
settings, paragraph settings and character settings. If my brain does
not trick me now, the style setting comes first and paragraph and
character settings specify exceptions to the style in that order.
Retrieving a CharacterRun lets HWPF take care of combining the
formatting "exceptions".

The question is probably a bit whether you want to extract formatting at
a few places or throughout the whole document. The Range based approach
is in my point of view good for the "few places". If you wish to do
search and replace, it feels a bit like you can live with checking a few
places only. If you need to look at a lot of places, I would recommend
another procedure - just drop a note in this case and I will provide
some hints.

Best wishes,
Rainer
-- 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/

Reply via email to