XWPF表单元格中的新段落 [英] XWPF new paragraph in a table cell
问题描述
我正在尝试创建一个只有一列的简单表.
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?
该表如下所示:
推荐答案
在创建单元格时,您还将创建一个空的段落,并且添加新段落最终会导致该单元格内有重复的段落.删除第一段/空段可以正常工作. 您应该尝试这样做:
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);
这篇关于XWPF表单元格中的新段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!