XWPF new paragraph in a table cell

杀马特。学长 韩版系。学妹 提交于 2019-12-14 03:03:26

问题


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:


回答1:


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);


来源:https://stackoverflow.com/questions/37002718/xwpf-new-paragraph-in-a-table-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!