You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by sanmoy <sa...@gmail.com> on 2011/07/31 07:09:28 UTC

problem regarding replace text from doc ( poi 3.8 beta release from download site )

Hi all,

I had written this simple piece of code

FileInputStream fileInputStream = new FileInputStream(new
File("C:\\in.doc"));
FileOutputStream fileOutputStream = new FileOutputStream(new
File("C:\\out.doc"));
HWPFDocument hwpfDocument = new HWPFDocument(fileInputStream);
Range range = hwpfDocument.getRange (); 
int numParagraph = range.numParagraphs();
for(int i=0;i&lt;numParagraph;i++)
{
      Paragraph paragraph = range.getParagraph(i);
      int numCharRuns = paragraph.numCharacterRuns();
      for(int j = 0; j &lt; numCharRuns; j++) 
      {
	    CharacterRun charRun = paragraph.getCharacterRun(j);
	    String text = charRun.text();
	    charRun.replaceText(text, &quot;added&quot;);
      }
}
hwpfDocument.write(fileOutputStream);

After the execution, the output file becomes corrupted ( tried to open with
office 2007) , input file was properly opening 

No exception thrown.
&lt;nabble_img src=&quot;snap.jpg&quot; border=&quot;0&quot;
alt=&quot;snap&quot;/&gt;



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/problem-regarding-replace-text-from-doc-poi-3-8-beta-release-from-download-site-tp4651292p4651292.html
Sent from the POI - User mailing list archive at Nabble.com.