poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hkcoder <hites...@thomsondigital.com>
Subject Apply different color to Paragraphs...
Date Wed, 15 Jun 2011 07:30:41 GMT

I'm working on the some text formatting in word document using POI API.
I want to change the paragraph color based on some conditions and cases.

like : 

I've used setColor() of CharacterRun class,but, it is not generating the
appropriate output. It is applying the Color to whole document text instead
of particular paragraph.

Below i've constructed a test program.

Here is my code snippet : 

     File file = new File("D:/testingword.doc");    
     POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
     HWPFDocument doc = new HWPFDocument(fs);
     Range range = doc.getRange;     
     WordExtractor we = new WordExtractor(doc);    
     String[] paragraphsArr = we.getParagraphText();
     for(int i=0;i&lt;paragraphsArr.length;i++)
         Paragraph pr = range.getParagraph(i);                                           
         CharacterRun cr=pr.getCharacterRun(0);         
		&lt;b&gt;//Don't apply color to first paragraph
             cr.setColor(6);//Applying red-color to the rest of paragraphs.
         System.out.println(" "+cr.getFontName()+" "+cr.getColor());
     OutputStream out = new FileOutputStream(new

I also tried with different ranges of HWPFDocument class, output is same in
that case also.
Is there any way to give different color to each paragraph? or any property
i'm missing?
Please comment.


View this message in context: http://apache-poi.1045710.n5.nabble.com/Apply-different-color-to-Paragraphs-tp4490387p4490387.html
Sent from the POI - Dev mailing list archive at Nabble.com.

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

View raw message