当前位置:网站首页>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
边栏推荐
- Net framework
- The 16th program design competition of Dalian University of Technology (Problem Solver)
- Verilog daily question (vl14 vending machine 1 -- FSM common question types)
- Verilog 每日一题 (VL24 多bit MUX同步器 跨时域输出)
- Why do I choose to use go language?
- 线性代数及矩阵论(十)
- Linear algebra and matrix theory (VIII)
- Linear algebra and matrix theory (7)
- Vscode界面介绍
- In some cases, error: (XX, XX) failed to resolve: XXXXXX.
猜你喜欢

连接设计与测试平台——SystemVerilog 接口知识点总结

Visual Studio 2012/2015发布Web应用连同.cs源码一起发布

Verilog daily question (vl27 settable counter)

Verilog 每日一题 (VL5 信号发生器)

Analysis of browser decoding process

MySQL数据库增删改查(基础操作命令详解)

Why do I choose to use go language?

Net framework

Shopee code League 2022 - qualification round p3.connecting the numbers (segment tree / bipartite graph determination, to be discussed)

The practice of the beego framework for goweb development: Section V project construction and user registration
随机推荐
Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
Encountered.Sqlite file processing during Android Development
Role of Fortress machine
Verilog 每日一题 (VL24 多bit MUX同步器 跨时域输出)
The 16th program design competition of Dalian University of Technology (Problem Solver)
influxdb2的使用
How do we do full link grayscale on the database?
C#遍历集合
Verilog 每日一题 (VL28 加减计数器)
Unity shader realizes water wave effect with noise texture
Selection of resistance in high speed circuit
The practice of beego framework in goweb development: Section I Introduction to beego framework
CNSA与CASC和CASIC的区别
WPF command button transparent style
Verilog daily question (vl6 data series to parallel circuit)
《Kubernetes》你需要掌握的 Service 和 Ingress
How to protect image security during construction
Linear algebra and matrix theory (VIII)
Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
Unity shader texture animation