我可以做如何证明表格中的段落是合理的

问题描述 投票:0回答:1
I正在使用Apache POI 4.1.2,并希望在表单元格中应用理由(双方对齐)。但是,它无法正常工作。

adding run.addbreak();启用理由,但它会创建一个额外的空白行。 删除Run.AddBreak();防止空白行,但理由不起作用。

XWPFRun run = paragraph.createRun(); run.setText(text); run.addBreak(); // ?? run.setFontSize(10);

有一个很好的解决方案吗?
adding run.addbreak();启用理由,但会产生额外的空白行。
    

必须有一个paragraphAlignment

设置。如果将其设置为两者,则将其设置为一种JustifyText
apache-poi cell
1个回答
0
投票

“当您证明文本合理时,在单词之间添加了空间,以便每行的两个边缘都与两个边距对齐。段落中的最后一行是对左对齐的。 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(); } }

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.