下面是核心代码段,可以根据要求进行改造,可以添加图片、表格内容。
1、相关的导出的依赖
<!-- excel工具 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
2、导出word的核心代码可以根据需要进行封装和修改。
public void exportWord(HttpServletResponse response,@PathVariable Long id) {
//创建一个word对象
XWPFDocument document = new XWPFDocument();
//创建一个段落
XWPFParagraph titleParagraph = document.createParagraph();
//将其居中成为标题段
titleParagraph.setAlignment(ParagraphAlignment.CENTER);
//创建一个文本对象