
This chapter takes you through the classes and methods of Apache POI for managing a Word document.
This is a marker interface (interface do not contain any methods), that notifies that the implemented class can be able to create a word document.
This is a class under org.apache.poi.xwpf.usermodel package. It is used to create MS-Word Document with .docx file format.
| Sr.No. | Method & Description | 
|---|---|
| 1 | commit() Commits and saves the document.  | 
| 2 | createParagraph() Appends a new paragraph to this document.  | 
| 3 | createTable() Creates an empty table with one row and one column as default.  | 
| 4 | createTOC() Creates a table of content for Word document.  | 
| 5 | getParagraphs() Returns the paragraph(s) that holds the text of the header or footer.  | 
| 6 | getStyle() Returns the styles object used.  | 
For the remaining methods of this class, refer the complete API document at −
Package org.apache.poi.openxml4j.opc.internal.
This is a class under org.apache.poi.xwpf.usermodel package and is used to create paragraph in a word document. This instance is also used to add all types of elements into word document.
| Sr.No. | Method & Description | 
|---|---|
| 1 | createRun() Appends a new run to this paragraph.  | 
| 2 | getAlignment() Returns the paragraph alignment which shall be applied to the text in this paragraph.  | 
| 3 | setAlignment(ParagraphAlignment align) Specifies the paragraph alignment which shall be applied to the text in this paragraph.  | 
| 4 | setBorderBottom(Borders border) Specifies the border which shall be displayed below a set of paragraphs, which have the same set of paragraph border settings.  | 
| 5 | setBorderLeft(Borders border) Specifies the border which shall be displayed on the left side of the page around the specified paragraph.  | 
| 6 | setBorderRight(Borders border) Specifies the border which shall be displayed on the right side of the page around the specified paragraph.  | 
| 7 | setBorderTop(Borders border) Specifies the border which shall be displayed above a set of paragraphs which have the same set of paragraph border settings.  | 
For the remaining methods of this class, refer the complete API document at −
This is a class under org.apache.poi.xwpf.usermodel package and is used to add a region of text to the paragraph.
| Sr.No. | Method & Description | 
|---|---|
| 1 | addBreak() Specifies that a break shall be placed at the current location in the run content.  | 
| 2 | addTab() Specifies that a tab shall be placed at the current location in the run content.  | 
| 3 | setColor(java.lang.String rgbStr) Sets text color.  | 
| 4 | setFontSize(int size) Specifies the font size which shall be applied to all noncomplex script characters in the content of this run when displayed.  | 
| 5 | setText(java.lang.String value) Sets the text of this text run.  | 
| 6 | setBold(boolean value) Specifies whether the bold property shall be applied to all non-complex script characters in the content of this run when displayed in a document.  | 
For the remaining methods of this class, refer the complete API document at −
This is a class under org.apache.poi.xwpf.usermodel package and is used to add different styles to the object elements in a word document.
| Sr.No. | Method & Description | 
|---|---|
| 1 | getNextStyleID() It is used to get StyleID of the next style.  | 
| 2 | getStyleId() It is used to get StyleID of the style.  | 
| 3 | getStyles() It is used to get styles.  | 
| 4 | setStyleId(java.lang.String styleId) It is used to set styleID.  | 
For the remaining methods of this class, refer the complete API document at −
This is a class under org.apache.poi.xwpf.usermodel package and is used to add table data into a word document.
| Sr.No. | Method & Description | 
|---|---|
| 1 | addNewCol() Adds a new column for each row in this table.  | 
| 2 | addRow(XWPFTableRow row, int pos) Adds a new Row to the table at position pos.  | 
| 3 | createRow() Creates a new XWPFTableRow object with as many cells as the number of columns defined in that moment.  | 
| 4 | setWidth(int width) Sets the width of the column.  | 
For the remaining methods of this class, refer the complete API document at: POI API Documentation
This is a class under org.apache.poi.xwpf.extractor package. It is a basic parser class used to extract the simple text from a Word document.
| Sr.No. | Method & Description | 
|---|---|
| 1 | getText() Retrieves all the text from the document.  | 
For the remaining methods of this class, refer the complete API document at: POI API Documentation