Add Paragraph to Word Doc Using POI

In the last post we saw how to Create Word Doc file in Java Using POI. Now in this post we will see how to add Paragraph to Word doc using POI.

Classes / Interfaces Used

XWPFDocument

org.apache.poi.xwpf.usermodel.XWPFDocument is used to create the MS Word Docs in the .docx formats.

XWPFParagraph

org.apache.poi.xwpf.usermodel.XWPFParagraph is used to create a paragraph in the word file.

XWPFRun

org.apache.poi.xwpf.usermodel.XWPFRun is used to add/change the text in a specified element/region.

The Code

Output

When we run the above code we get the message on the console and a word document is created at the location we had specified.

Add Paragraph to Word Doc Using POI

In the coming posts we will see some of the other fun stuff that we can do with Word documents using Apache POI.

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn