poi-tl根据word模板导出word、使用spring-thymeleaf模板生成html并通过docx4j把html转word,使用jxls根据excel模板导出excel(2)

poi-tl根据word模板导出word、使用spring-thymeleaf模板生成html并通过docx4j把html转word,使用jxls根据excel模板导出excel(2)

thymeleaf

官网

https://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html 

参考

https://blog.csdn.net/u010739551/article/details/81566987

Thymeleaf是用于Web和独立环境的现代服务器端Java模板引擎。

Thymeleaf的主要目标是将优雅的自然模板带到您的开发工作流程中—HTML能够在浏览器中正确显示,并且可以作为静态原型,从而在开发团队中实现更强大的协作。Thymeleaf能够处理HTML,XML,JavaScript,CSS甚至纯文本。

Thymeleaf的主要目标是提供一个优雅和高度可维护的创建模板的方式。 为了实现这一点,它建立在自然模板的概念之上,以不影响模板作为设计原型的方式将其逻辑注入到模板文件中。 这改善了设计沟通,弥合了前端设计和开发人员之间的理解偏差。

自动生成WORD文档并下载,导出WORD文档 thymeleaf
*  配置jxls后thymeleaf不好使 因thymeleaf默认找后缀为.html的模板  而jxls  指定了后缀为 .xls  所以不能使用Mode直接返回视图 需通过spring thymeleaf 把docx4j转word并下载
*  所以thymeleaf找不到相关模板  解决方案为demo2  通过docx4j 使  html 转word 并下载

docx4j

官网

https://www.docx4java.org/trac/docx4j 

例子

https://github.com/plutext/docx4j/tree/master/docx4j-samples-docx4j   
 

欢迎使用docx4j

docx4j是一个开源(ASLv2)Java库,用于创建和处理Microsoft Open XML(Word docx,Powerpoint pptx和Excel xlsx)文件。

它类似于Microsoft的OpenXML SDK,但适用于Java。docx4j使用JAXB创建内存中的对象表示形式。

它的重点是功能:如果文件格式支持它,则可以使用docx4j来实现。但是首先,您需要花一些时间来了解JAXB和Open XML文件结构

docx4j由Plutext Pty Ltd于2008年创建-将OpenXML4J用于OPC。Plutext仍然推动着该项目的发展,但是从那时起docx4j受益于许多个人的贡献。贡献者列在docx4j的pom.xml中。

docxj4简介

“现在有了docx4j,使用我设想的方法生成Word文档要容易得多。”

“过去一个月我一直在新产品上使用docx4j,我对docx4j的使用量印象深刻并感到感谢。”

“该库为您提供了从Java创建/加载/编辑/编写Word docx文档所需的一切,并附带了Maven仓库,在线Javadoc和不错的示例代码集。您还需要什么呢?:-

thymeleaf

1.导入依赖

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

    <!--docx4j start-->
        <dependency>
            <groupId>org.docx4j</groupId>
            <artifactId>docx4j-ImportXHTML</artifactId>
            <version>8.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.docx4j</groupId>
            <artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
            <version>8.0.0</version>
        </dependency>
        <!--docx4j start-->

2.模板

thymeleafDemo1.html模板

<html lang="zh_CN">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <title>Hello report.</title>
</head>
<body>
<h1 data-th-text="${hello}">Hello report.</h1>
<br/>
<br/>
<img  src="https://img-blog.csdnimg.cn/2022010622205164259.png"  class="header-logo"/>
<br/>
<h1>base64Image写死图片base64</h1>
<img src=""
     data-th-src="${base64Image}"
     width="80px"
     height="60px"/>

<br/>
<h1>imagData</h1>
<img src=""
     data-th-src="${imagData}"
     width="80px"
     height="60px"/>

<br/>
<h1>imagData2</h1>
<img src=""
     data-th-src="${imagData2}"
     width="80px"
     height="60px"/>
<br/>
<table>
    <thead>
    <tr>
        <th>id</th>
        <th>信息</th>
        <th>日期</th>
        <th>图片</th>
    </tr>
    </thead>
    <tbody>
    <tr data-th-each="hel : ${hellos}">
        <th data-th-text="${hel.id}">id</th>
        <th data-th-text="${hel.hello}">message</th>
        <th data-th-text="${#dates.format(hel.date, 'yyyy-MM-dd HH:mm')}">date</th>
        <th>
            <!--<img src="https://img-blog.csdnimg.cn/2022010622205261527.png"-->
                 <!--data-th-src="${base64Image}"-->
                 <!--data-th-title="'title_' + ${hel.hello}" title="title"-->
                 <!--data-th-alt="'title_' + ${hel.hello}"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值