当前位置:网站首页>Export word according to the template, generate compound format tables and variable column tables
Export word according to the template, generate compound format tables and variable column tables
2022-07-28 17:26:00 【wangxudongx】
List of articles
Chapter one :springboot Generate complex under word Document scheme stay Word Make templates in the software
The third chapter :doc and docx Insert multi graph
Chapter four :web In the environment word Document preview
Export... Based on template word, Compound format table generation 、 Variable column table generation
Preface
This time, let's implement compound format tables and variable column tables , The effect is as follows
The following is the main body of this article , The following cases can be used for reference
Compound format table

One 、 Take apart word xml Document labels

As required, we can send the form Split by behavior unit Table rows in four formats ;
We are at this time xml These four lines are reserved in the template file for use .
Table traversal logic
<w:tbl>
<!-- Header row begin -->
<w:tr>...</w:tr>
<!-- Header row end -->
<#list complexTable.rows as tableRow>
<#if !tableRow_has_next>
<!-- The last line of the table begin -->
<w:tr>...</w:tr>
<!-- The last line of the table end -->
<#elseif tableRow_has_next && tableRow_index == 0 >
<!-- First row of table content begin -->
<w:tr>...</w:tr>
<!-- First row of table content end -->
<#else >
<!-- Middle row of table content begin -->
<w:tr>...</w:tr>
<!-- Middle row of table content end -->
</#if>
</#list>
</w:tbl>
The above code logic can be compatible with a piece of data , In the case of two pieces of data and multiple lines of data, the format will not be disordered , Please see the following test results for the operation effect .
Data structure definition
{
"columns": [
" Name 1",
" Name 2"
],
"rows": [
{
"cell1": " Xiaohong ",
"cell2": " Woman "
},
{
"cell1": " Xiao Ming ",
"cell2": " male "
}
......
{
"cellFinal": " Cheerleading , I can define fields at will , As long as the composite template split logic "
}
]
}
row The data structure of the last row is different from the above , In fact, it can also be defined as the same , Just according to our disassembly logic , The last line takes only one field , So I defined another structure to store , In fact, as long as you can get it in the template .
Two 、 result
A line of data

Two lines of data

Multi row data

Variable length column format table
A table with an indefinite number of columns .
Disassembly logic
Tables with variable length columns are mainly Add another one inside the line list loop , then Control the format in columns , Generally, you only need to control the leftmost and last columns of each row .
<w:tbl>
<!-- Header row begin -->
<w:tr>
<#list complexTable.columns as column>
<w:tc>...
<w:t>${column}</w:t>
...</w:tc>
</#list>
</w:tr>
<!-- Header row end -->
<#list complexTable.rows as tableRow>
<#if !tableRow_has_next>
<!-- The last line of the table begin -->
<w:tr>...
<#list tableRow as cell>
<w:tc>...
<!-- If the outer border of the table is different from the inner border, you need to add ifelse Code , First column adjust left border , The last column adjusts the right border ; <w:tcBorders> <w:top w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="000000"/> <w:left w:val="dash-dot-stroked" w:sz="24" wx:bdrwidth="60" w:space="0" w:color="auto"/> <w:bottom w:val="dash-dot-stroked" w:sz="24" wx:bdrwidth="60" w:space="0" w:color="auto"/> <w:right w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="000000"/> </w:tcBorders> -->
<w:t>${cell}</w:t>
...</w:tc>
</#list>
...</w:tr>
<!-- The last line of the table end -->
<#elseif tableRow_has_next && tableRow_index == 0 >
<!-- First row of table content begin -->
<w:tr>...</w:tr>
<!-- First row of table content end -->
<#else >
<!-- Middle row of table content begin -->
<w:tr>...</w:tr>
<!-- Middle row of table content end -->
</#if>
</#list>
</w:tbl>
Data structure definition
{
"columns": [
" Name 1",
" Name 2"
],
"rows": [
[
" data 1",
" data 2"
],
[
" data 1",
" data 2"
]
]
}
summary
In the last chapter, we talked about the generation method of fixed format tables and pictures ; In this chapter, we explain how to generate “ Compound format table ” and “ Variable column table ”, This is enough for me to deal with a large number of application scenarios , If there are more complex scenes , for instance “ Variable column plus compound format, and then some columns need fixed width ” Such a need , We can combine the above solutions , Close test available .
Code warehouse
https://gitee.com/whatitis/springboot_freemarker_word
The test entrance is :
cn.gitee.worddemo.WorddemoApplicationTests#testProc2
边栏推荐
- 【presto】presto 常用的命令
- Verilog 每日一题 (VL24 多bit MUX同步器 跨时域输出)
- 【atlas】atlas 编译报错整理(全)
- CNSA与CASC和CASIC的区别
- 【CDH】通过 ClouderaManager 配置CDH组件用 prometheus 监控采集JMX信息
- 高速电路中电感的选型和应用
- 侦察机与预警机的区别
- Goweb开发之Beego框架实战:第三节 程序执行流程分析
- Goweb开发之Beego框架实战:第四节 数据库配置及连接
- Wechat applet cash red packet returns the error "the IP address is not the available IP address you set on the merchant platform". The ultimate solution
猜你喜欢

Verilog 每日一题 (VL24 多bit MUX同步器 跨时域输出)

Verilog daily question (vl28 plus and minus counter)

GEAR: Graph-based Evidence Aggregating and Reasoning for Fact Verification

高速电路设计实践——概述

线性代数及矩阵论(七)

Use Alibaba cloud's free SSL certificate

在android开发过程中遇到.sqlite文件处理

微信小程序现金红包返回“IP地址非你在商户平台设置的可用IP地址”错误终极解决方法

valarray数值库学习

The actual combat of the beego framework of goweb development: Section III program execution process analysis
随机推荐
微信小程序现金红包返回“IP地址非你在商户平台设置的可用IP地址”错误终极解决方法
Analysis of browser decoding process
Microservice Architecture - service registry and service gateway (6.8) (Reprint)
全链路灰度在数据库上我们是怎么做的?
Unity shader cartoon style rendering
带参数的微信小程序二维码生成
Linear algebra and matrix theory (7)
异步FIFO基本原理(基于Verilog的简单实现)
Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
Goweb开发之Beego框架实战:第四节 数据库配置及连接
Difference between reconnaissance aircraft and early warning aircraft
Kubernetes service and ingress you need to master
火了 2 年的服务网格究竟给微服务带来了什么?(转载)
In some cases, error: (XX, XX) failed to resolve: XXXXXX.
Verilog daily question (vl27 settable counter)
Several methods of importing excel file data by C #
LNMP源码编译安装
C# 导入Excel文件数据的几种方法
The practice of beego framework in goweb development: Section I Introduction to beego framework
高速电路中电感的选型和应用