123456
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>5.2.3</version></dependency>
12345678
XWPFDocument document = new XWPFDocument(); //创建了一个新的空白 Word 文档XWPFParagraph Paragraph = document.createParagraph(); //这行代码创建了一个新的段落对象,并将其添加到刚刚创建的 Word 文档中Paragraph.setAlignment(ParagraphAlignment.CENTER); //设置对齐方式XWPFRun run = Paragraph.createRun(); //XWPFRun 对象代表 Word 文档中的一个文本运行(run),可以通过操作这个文本运行对象来设置文本内容、样式、字体等属性。run.setText("hello world"); //这里是输入到word的文本run.setBold(true); //设置字体加粗run.setFontSize(20); //设置字体大小(12磅对应小四)