Hi Team,

I am using Apache POI to replace some data in Doc file format.

If the doc file contains *expanding/collapsing headings *and the replaceable
string occurs before that heading in the context then after replacing the
string the new Doc file generated is corrupt.

As per my findings if the /location of  expanding/collapsing headings link's
position changes due to some replace/ then it leads to file corruption.

Code Snippet:
                HWPFDocument document = new HWPFDocument(fileInputStream);
                Range range = document.getRange();

                //Word-Extractor
                WordExtractor we = new WordExtractor(document);

                //get paragraphs array 
                String[] paragraphArray = we.getParagraphText();

                //traverse through each paragraph
                
                for (int i = 0; i < paragraphArray.length; i++) {
                        
                        Paragraph paragraph2 = range.getParagraph(i);
                        paragraph2.replaceText(paragraph2.text(), "Replacing 
String");

                }
                document.write(fileOutputStream);       


Please help me in fixing this issue.

Thanks in advance.




--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Doc-file-corruption-containing-expanding-collapsing-headings-tp5715807.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to