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
Hi,

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 : 
P1(RedColor)
p2(GreenColor)

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);         
         if(i==0)
         {
		&lt;b&gt;//Don't apply color to first paragraph
         }
         else
         {   
             cr.setColor(6);//Applying red-color to the rest of paragraphs.
         }
         System.out.println(" "+cr.getFontName()+" "+cr.getColor());
     }     
     OutputStream out = new FileOutputStream(new
File("D:/testingword_out.doc"));
     doc.write(out);
     out.flush();
     out.close();

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


Mime
View raw message