当前位置:网站首页>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
边栏推荐
- Modeling Semantics with Gated Graph Neural Networks for KBQA
- Pytorch Foundation: similarities and differences between torch.mul, torch.mm and torch.matmul
- Round 1C 2022 - Code jam 2022 b.square (Mathematics, thinking)
- Atcoder beginer contest 240 g.reporting Takahashi (classical problems of Combinatorial Mathematics)
- Cf/atc/lc topic score website
- How do we do full link grayscale on the database?
- Codeforces round 768 (Div. 2) e.paint the middle (greedy / interval relationship processing)
- Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
- The practice of the beego framework for goweb development: Section V project construction and user registration
- 微服务架构-服务注册中心和服务网关(6.8) (转载)
猜你喜欢

High speed circuit design practice -- Overview

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 每日一题 (VL5 信号发生器)

Asynchronous circuit design -- principle and example of synchronous pulser

The practice of beego framework in goweb development: Section I Introduction to beego framework

UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)G. GCD cost on the tree

Valarray Library Learning

LNMP源码编译安装

Proof of the third scene (f) in 22 years

Unity shader realizes water wave effect with noise texture
随机推荐
Shopee code League 2022 - qualification round p3.connecting the numbers (segment tree / bipartite graph determination, to be discussed)
Goweb开发之Beego框架实战:第四节 数据库配置及连接
DGL Chapter 1 (official tutorial) personal notes
Use Alibaba cloud's free SSL certificate
Verilog daily question (vl26 simple stopwatch)
Unity shader depth of field effect
Linear algebra and matrix theory (IX)
Reasoning Over Semantic-Level Graph for Fact Checking
零基础利用Unity3D开发AR应用并远程下载3D模型
Verilog 每日一题(VL26 简易秒表)
MySQL详细学习教程(建议收藏)
Make full use of English
Selection and application of capacitor in high speed circuit -- detailed explanation
Selection and application of inductors in high speed circuits
Problem solution of code heartstrings Junior Group (official competition) of Dalian University of Technology (Development Zone campus) in 2021
Verilog daily question (vl8 uses generate... For statement to simplify code)
Visual Studio 2012/2015发布Web应用连同.cs源码一起发布
What does the service grid that has been popular for two years bring to microservices? (Reprinted)
The maximum recommended number of rows for MySQL is 2000W. Is it reliable?
部分情况下Error:(xx, xx) Failed to resolve: xxxxxx解决。