adding run.addbreak();启用理由,但它会创建一个额外的空白行。 删除Run.AddBreak();防止空白行,但理由不起作用。
XWPFRun run = paragraph.createRun();
run.setText(text);
run.addBreak(); // ??
run.setFontSize(10);
有一个很好的解决方案吗?adding run.addbreak();启用理由,但会产生额外的空白行。
必须有一个paragraphAlignment
设置。如果将其设置为两者,则将其设置为一种JustifyText“当您证明文本合理时,在单词之间添加了空间,以便每行的两个边缘都与两个边距对齐。段落中的最后一行是对左对齐的。
that是如何工作的。
也是“分发文本”的设置。可以使用ParagraphAlignment.DISTRIBUTE
设置。 GUI一词仅在需要将其添加到Microsoft Office的语言时提供此设置。例如,添加语言中文(传统)将导致这一点。
遵循完整的示例显示了
ParagraphAlignment.BOTH
和
ParagraphAlignment.DISTRIBUTE
。
import java.io.*;
import org.apache.poi.xwpf.usermodel.*;
public class WordTableParagraphAlignmentBOTHvsDISTRIBUTE {
public static void main(String[] args) throws Exception {
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("The table ParagraphAlignmentBOTH vs. DISTRIBUTE:");
XWPFTable table = document.createTable();
table.setWidth("100%");
XWPFTableRow tableRow = table.getRow(0);
tableRow.getCell(0).setText("ParagraphAlignment.BOTH: When you justify text, space is added between words so that both edges of each line are aligned with both margins. The last line in the paragraph is aligned left.");
tableRow.getCell(0).getParagraphs().get(0).setAlignment(ParagraphAlignment.BOTH);
tableRow.getCell(0).setWidth("50%");
tableRow.addNewTableCell().setText("ParagraphAlignment.DISTRIBUTE: Using this also in last line of paragraph space is added between words and letters so that both edges of each line are aligned with both margins.");
tableRow.getCell(1).getParagraphs().get(0).setAlignment(ParagraphAlignment.DISTRIBUTE);
tableRow.getCell(1).setWidth("50%");
FileOutputStream out = new FileOutputStream("./result.docx");
document.write(out);
out.close();
document.close();
}
}