You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by raju0028 <na...@gmail.com> on 2014/03/14 08:43:29 UTC
Re: [Bug 53307] New: How to read and write a .docx file using XWPF
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [Bug 53307] New: How to read and write a .docx file using XWPF
Posted by Nitin Chopkar <ni...@yahoo.co.in>.
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 <na...@gmail.com> 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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org