本文概述
- Apache POI Word对齐示例
ParagraphAlignment.RIGHT将段落右对齐。
ParagraphAlignment.LEFT将段落左对齐。
ParagraphAlignment.CENTER将段落与中心对齐。
让我们看一个例子,其中我们将文本向左对齐。
Apache POI Word对齐示例
package poiexample;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class AligningExample {
public static void main(String[] args) {
XWPFDocument doc = new XWPFDocument();
try(OutputStream os = new FileOutputStream("srcmini.docx")) {
XWPFParagraph paragraph = doc.createParagraph();
paragraph.setAlignment(ParagraphAlignment.RIGHT);
XWPFRun run = paragraph.createRun();
run.setText("Text is aligned right");
doc.write(os);
}catch(Exception e) {
System.out.println(e);
}
}
}
【apache poi word对齐】输出:
文章图片
推荐阅读
- apache poi word风格
- apache poi word提取文本
- apache poi word提取段落
- apache poi和powerpoint
- apache poi创建ms word文档
- apache poi microsoft word文档
- apache poi的注释
- apache poi样式化形状
- apache poi重写