Home » Apache POI Word Table

Apache POI Word Table

by Online Tutorials Library

Apache POI Word Table

To create table in Word document, we can use XWPFTable class located into org.apache.poi.xwpf.usermodel.XWPFTable package. Apache POI added one more class XWPFTableRow for creating row.

See, below we have created a table in word document using Java program.

Apache POI XWPFTable Methods

Following are the commonly used methods to handle table in the document.

Method Description
public void addNewCol() It adds a new column for each row in this table.
public void addRow(XWPFTableRow row) It adds a new Row to the table.
public XWPFTableRow createRow() It creates a new XWPFTableRow object with as many cells as the number of columns defined in that moment
public java.lang.String getText() It is used to extract text in cells.
public void setWidth(int width) It is used to set width.
public int getNumberOfRows() It is used to get number of rows in table.

Apache POI Word Table Example

Output:

Apache POI Word Table

You may also like