表格单元格中的 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屋!