写XWPFTable单元时的Java的Apache POI换行符被忽略 [英] Java Apache POI newline characters are ignored when writing to XWPFTable cell
问题描述
希望有人可能有一些这方面的经验。我使用的Apache POI 3.8b4输出表在Word 2007格式。当我做类似下面的内容:
XWPFTableRow行= table.getRow(0);
字符串文本=A \\ NB \\ NC \\ ND;
row.getCell(I).setText(文本);
我所有的换行符都在表格单元的输出忽略看起来像
A B C D
有没有人有任何想法如何得到它正确地显示为
A
乙
C
ð
编辑:
解决的办法是以下内容:
XWPFParagraph第= row.getCell(I).getParagraphs()得到(0);
对于(字符串文本:myStrings){
XWPFRun运行= para.createRun();
run.setText(text.trim());
run.addBreak();
}
你有没有尝试添加多个段落?
<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/xwpf/usermodel/XWPFTableCell.html#addParagraph%28org.apache.poi.xwpf.usermodel.XWPFParagraph%29\"相对=nofollow>添加段落
Hoping someone might have some experience with this. I'm using Apache POI 3.8b4 to output a table in Word 2007 format. When I do something similar to the following:
XWPFTableRow row = table.getRow(0);
String text = "A\nB\nC\nD";
row.getCell(i).setText(text);
all of my line breaks are ignored in the output in the table cell looks like
A B C D
Does anyone have any idea how to get it to properly display as
A
B
C
D
Edit: The solution was the following:
XWPFParagraph para = row.getCell(i).getParagraphs().get(0);
for(String text : myStrings){
XWPFRun run = para.createRun();
run.setText(text.trim());
run.addBreak();
}
Have you tried adding multiple Paragraphs?
这篇关于写XWPFTable单元时的Java的Apache POI换行符被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!