You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by rnichol7 <rn...@hotmail.com> on 2012/02/07 23:46:09 UTC

When using XWPFTable the first two rows (0,1) appear on the same line

I am trying to create a table with 5 rows and 3 columns.  The data on row 0
and row 1 both appear on the top line of the table (leaving the last row
empty).  I have been playing around with the 'simpleTable' example, and get
the same results whether I use the .getRow() method, or explicitly create
XWPFTableRows.

So here is the source code:

import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.*;
import java.io.FileOutputStream;


public class SimpleTable {
    public static void main(String[] args) throws Exception {
        XWPFDocument doc = new XWPFDocument();
        XWPFTable table=doc.createTable(3,3);

        XWPFParagraph p1 = doc.createParagraph();
 
        table.getRow(0).getCell(0).setText("hi0");
        table.getRow(0).getCell(1).setText("Hi!0");
        table.getRow(0).getCell(2).setText("EXAMPLE OF TABLE0");

        table.getRow(1).getCell(0).setText("EXAMPLE OF TABLE1");
        table.getRow(1).getCell(1).setText("only text1");
        table.getRow(1).getCell(2).setText("More text1");

        table.getRow(2).getCell(0).setText("EXAMPLE OF TABLE2");
        table.getRow(2).getCell(1).setText("only text2");
        table.getRow(2).getCell(2).setText("More text2");

        //second attempt
        XWPFTable t2 = doc.createTable(2,2);

        XWPFTableRow tableOneRowOne = t2.getRow(0);
        tableOneRowOne.getCell(0).setText(" Author1: ");
        tableOneRowOne.getCell(1).setText(" Author2: ");

        XWPFTableRow tableOneRowTwo = t2.getRow(1);
        tableOneRowTwo.getCell(0).setText(" Roger Nichols ");
        tableOneRowTwo.getCell(1).setText(" Roger M. Nichols ");

        FileOutputStream out = new FileOutputStream("simpleTable.docx");
        doc.write(out);
        out.close();
    }
}


The table(s) end up looking like:


  

    	hi0EXAMPLE OF TABLE1	Hi!0only text1	EXAMPLE OF TABLE0More text1
  
  

    	EXAMPLE OF TABLE2	only text2	More text2
  
  

    	&nbsp;	&nbsp;	&nbsp;
  

		
Any help would be appreciated, I need tables in a bad way for the project I
am working on...

Thank you,

RMN

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/When-using-XWPFTable-the-first-two-rows-0-1-appear-on-the-same-line-tp5464870p5464870.html
Sent from the POI - User mailing list archive at Nabble.com.