suppose i have html contents have to write into doc or docx file. that html 
having images also. using POI





On Friday, 14 March 2014 3:14 PM, raju0028 <[email protected]> wrote:
 
hi ,here you are  casting list of paragraphs to XWPFParagraph object so you
get exception like that

this is not correct ====


XWPFParagraph pr = (XWPFParagraph)doc.getParagraphs(); 





so you can try this code:
here i am working on ubuntu thats why  i am giving file path like that.  

public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub


        XWPFDocument doc = new XWPFDocument(new
FileInputStream("/home/sundaricore/Downloads/test.docx"));

        XWPFDocument destDoc =new XWPFDocument();

        OutputStream  out = new
FileOutputStream("/home/sundaricore/Downloads/testDemo.docx");
        List<XWPFParagraph> paragraphs=doc.getParagraphs();
        for (XWPFParagraph par : paragraphs) {
            XWPFParagraph tmpParagraph = destDoc.createParagraph();
            tmpParagraph.setAlignment(ParagraphAlignment.LEFT);
            tmpParagraph.setSpacingBefore(2); 
            XWPFRun tmpRun = tmpParagraph.createRun();
            XmlCursor c2 = tmpParagraph.getCTP().newCursor();
            tmpRun.setText(par.getText());
            tmpRun.addBreak();
        }
        

        //String copy=pr.getText();


        destDoc.write(out);
}



--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Bug-53307-New-How-to-read-and-write-a-docx-file-using-XWPF-tp5709954p5715171.html
Sent from the POI - Dev mailing list archive at Nabble.com.

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

Reply via email to