用 whitespaces/enters 将文本和表格写入 word
Write text and tables in to word, with whitespaces/enters
我正在将 tables
中的 text
和 text
写入 word 文档。
用下面的代码把tables
放在右边paragraphs
下面。
Iterator<IBodyElement> iter = xdoc.getBodyElementsIterator();
while (iter.hasNext())
{
IBodyElement elem = iter.next();
if (elem instanceof XWPFParagraph)
{
relevantText.setText(((XWPFParagraph) elem).getText());
} else if (elem instanceof XWPFTable)
{
tabellen.setText(((XWPFTable) elem).getText());
}
}
现在,当我尝试用 addBreak()
或 addCarriageReturn()
创建 whitespace/enter
时,我的文档顺序是错误的。 table text
放在所有 text
.
之后
有人解决这个问题吗?
几天前我遇到了同样的问题。您是否为段落和表格创建了 2 个不同的 运行?
因为我这样做了,当我将其更改为 1 运行 时,它确实对我有用。
像这样:
XWPFRun text = paragraph.createRun();
我正在将 tables
中的 text
和 text
写入 word 文档。
用下面的代码把tables
放在右边paragraphs
下面。
Iterator<IBodyElement> iter = xdoc.getBodyElementsIterator();
while (iter.hasNext())
{
IBodyElement elem = iter.next();
if (elem instanceof XWPFParagraph)
{
relevantText.setText(((XWPFParagraph) elem).getText());
} else if (elem instanceof XWPFTable)
{
tabellen.setText(((XWPFTable) elem).getText());
}
}
现在,当我尝试用 addBreak()
或 addCarriageReturn()
创建 whitespace/enter
时,我的文档顺序是错误的。 table text
放在所有 text
.
有人解决这个问题吗?
几天前我遇到了同样的问题。您是否为段落和表格创建了 2 个不同的 运行?
因为我这样做了,当我将其更改为 1 运行 时,它确实对我有用。
像这样:
XWPFRun text = paragraph.createRun();