java XWPF POI如何设置段落中的文本而不使用换行符
XWPF第POI- 我想创建一个段落,但在该段落的最后一个文本或最后一行中没有文字包装。 如何设置。。。。。 谢谢
String kalimat="Aaaa bbb ccc ddd eee fffffff ggg hhh. Jjjjj kkk lll mmm nnnn oo pppppp qqqqq rrrr sssssssss tt uuu.";
paragraph = document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.BOTH);
paragraph.setSpacingBefore(0);
paragraph.setSpacingAfter(0);
paragraph.setSpacingBetween(1.5);
run = paragraph.createRun();
run.setFontFamily("Bookman Old Style");
run.setFontSize(12);
run.addTab();
run.setText(kalimat);
paragraph = document.createParagraph();
**//paragraph.setWordWrap(false);**
//paragraph.setWordWrapped(false);
paragraph.setAlignment(ParagraphAlignment.BOTH);
paragraph.setSpacingBefore(0);
paragraph.setSpacingAfter(0);
paragraph.setSpacingBetween(1.5);
run = paragraph.createRun();
run.setFontFamily("Bookman Old Style");
run.setFontSize(12);
run.setText("---------------------------------------------------------------------------------------------------------------------------------------------");
# 1 楼答案
Word通常无法将“全部换行”设置为“不换行”。它永远不会在页边距中打印内容,除非在页面边框中设置了缩进。当然,它也从不打印超出页面大小的内容
所以唯一的可能是将段落缩进设置为负数,这意味着进入页面边距。例如,将右段落缩进设置为-6英寸意味着此缩进将进入右页边距6英寸
但就你的例子而言,我怀疑你想在一段下面划线。这不应该使用ASCII art(
)来完成,但最好使用适当的段落设置
但从你们前面的问题中,我可以看出你们也希望有一个对齐的段落,在最后一行的右边空白处有填充字符(前导字符)。这可以通过在右页边距位置使用制表位来实现。但是页面大小和页边距需要明确设置。直到现在
apache poi
还没有完全支持这一点。因此,需要使用低级别的ooxml-schemas
类示例(使用
apache poi 4.0.1
)显示了所有内容:结果: