设为首页 加入收藏

TOP

SpringBoot导出Word文档的三种方式(一)
2023-07-25 21:28:11 】 浏览:189
Tags:SpringBoot 导出 Word 文档的 方式

SpringBoot导出Word文档的三种方式

一、导出方案

.doc      application/msword
.dot      application/msword
 
.docx     application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx     application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm     application/vnd.ms-word.document.macroEnabled.12
.dotm     application/vnd.ms-word.template.macroEnabled.12
 
.xls      application/vnd.ms-excel
.xlt      application/vnd.ms-excel
.xla      application/vnd.ms-excel
 
.xlsx     application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx     application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm     application/vnd.ms-excel.sheet.macroEnabled.12
.xltm     application/vnd.ms-excel.template.macroEnabled.12
.xlam     application/vnd.ms-excel.addin.macroEnabled.12
.xlsb     application/vnd.ms-excel.sheet.binary.macroEnabled.12
 
.ppt      application/vnd.ms-powerpoint
.pot      application/vnd.ms-powerpoint
.pps      application/vnd.ms-powerpoint
.ppa      application/vnd.ms-powerpoint
 
.pptx     application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx     application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx     application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam     application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm     application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm     application/vnd.ms-powerpoint.template.macroEnabled.12
.ppsm     application/vnd.ms-powerpoint.slideshow.macroEnabled.12
 
.mdb      application/vnd.ms-access

二、富文本转换后的HTML下载为Word文档

1、准备

  • 业务需求

    • 前端使用富文本插件生成带HTML标签的word文档,然后需要下载这个word文档。
    • 每个word文档的格式是可变的
  • 扩展业务需求:

    • 甚至可以去替换HTML的Word中的内容,然后导出需要的文档;缺点:替换字符串麻烦、而且HTML的Word的标签还需要研究。
    • 基于上述的业务需求。建议使用模板技术导出(也就是“三”)
  • 参考:

  • 导出结果

2、实现

2.1、导包

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>4.1.2</version>
</dependency>

2.2、HTML的word文档

package com.cc.ewd.html;

/**
 * @author CC
 * @since 2023/4/24 0024
 */
public interface HtmlConstants {

    /**
     * 普通文档(富文本生成的)
     */
    String HTML1 = "<h1 style=\"text-align: center;\"><strong>文章标题</strong></h1><h1><strong>一、标题1" +
            "</strong></h1><p><strong> &nbsp; &nbsp; &nbsp; 我是数据:{NUM}</strong></p><h2><strong>" +
            "1.1、吾问无为谓</strong></h2><table style=\"width: 100%;\">" +
            "<tbody><tr><th colSpan=\"1\" rowSpan=\"1\" width=\"auto\">序号</th>" +
            "<th colSpan=\"1
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/16/16
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java练手项目(尚硅谷的),不涉.. 下一篇Java中数字相关的类有哪些?Nuber..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目