5

I am trying to create a simple table with one column.

I create a new row and in each row a new paragraph. The problem is that each row starts with one empty line - I guess the new paragraph creates it.

I was trying to set spacing before, indentation etc. with no success.

       for (int i=0; i<questions.size(); i++) {
            Question question = questions.get(i);
            XWPFTableRow row = table.getRow(i);
            XWPFTableCell cell = row.getCell(0);

            XWPFParagraph paragraph = cell.addParagraph();
            XWPFRun run = paragraph.createRun();
            run.setText(question.getQuestion());
        }

Does a new paragraph create a new empty line?

The table looks like that:

Piotr Sagalara
  • 2,247
  • 3
  • 22
  • 25
  • Could your cell already have a paragraph in it? – Gagravarr May 03 '16 at 14:23
  • I'm not familiar with the library you're using, but I do know that a table cell in Word automatically contains a paragraph. It's combined with the end-of-cell marker (the little "sunshine" in each table cell). So if you explicitly add an additional paragraph, that will add a "line" to the table cell. You might see if a Run can be appended to a Cell in the library you're using? – Cindy Meister May 03 '16 at 14:40

1 Answers1

5

When you create a cell you are also creating an empty paragraph, and adding a new paragraph ends up in having duplicated paragraph inside the cell. Removing the first/empty paragraph works fine. You should try this:

table.getRow(0).getCell(0).removeParagraph(0);
Jose1755
  • 378
  • 3
  • 10