当前位置:网站首页>EasyExce template filling generation of Excel of actual operation, many processing sheet page
EasyExce template filling generation of Excel of actual operation, many processing sheet page
2022-07-29 20:33:00 【Beautiful Kun Shanghai Branch Kun】
之前使用word作为文件模板,Add variable generationword文件,现在需要使用ExcelGenerated as file template fill variableExcel,Consider using domestic ones firstesayExcelDo fill generation,easyExcel官网地址
https://easyexcel.opensource.alibaba.com/docs/current/

Let's take a look at the template information I need to make here,Normal variables are included here,Table loop and picture display,template file letter 息如下

Screenshot of the generated file

具体代码如下,这里需要注意There are also variables after the table loop的话,The filled configuration must be this
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
会自动换行
package com.example.demo.util;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.enums.WriteDirectionEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.metadata.fill.FillWrapper;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author qiankun.hu
* @version 1.0.0
* @createTime 2022年07月26日 13:47:00
* @Description easyExcel模板填充
*/
public class EasyExcelUtil {
public static void main(String[] args) throws MalformedURLException {
List<Map<String, Object>> paramValueMapListNew = new ArrayList<>();
for (int i = 0; i < 2; i++) {
Map<String, Object> cmap = new HashMap<>();
cmap.put("id", i);
cmap.put("name", "药品" + i);
cmap.put("guige", i +"ml" );
paramValueMapListNew.add(cmap);
}
long begin = System.currentTimeMillis();
//Set output stream and template information
ExcelWriter excelWriter = EasyExcel.write("D:\\workSpace\\66.xlsx").withTemplate("D:\\workSpace\\easy模板1.xlsx").build();
WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build();
//开启自动换行,Word wrap means writing one line at a timelistData is regenerated with a blank line,此选项默认是关闭的,需要提前设置为true
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
excelWriter.fill(new FillWrapper("user", paramValueMapListNew), fillConfig, writeSheet0);
excelWriter.fill(new FillWrapper("site", paramValueMapListNew), fillConfig, writeSheet0);
FillConfig fillConfig2 = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
excelWriter.fill( paramValueMapListNew, fillConfig2, writeSheet0);
Map<String, Object> map = new HashMap<>();
map.put("title", "Drug recall record sheet");
map.put("total", 1000);
map.put("time", "2022年07月22日13:28:28");
map.put("image", new URL("https://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fimg.jj20.com%252Fup%252Fallimg%252F4k%252Fs%252F02%252F2109242306111155-0-lp.jpg%26refer%3Dhttp%253A%252F%252Fimg.jj20.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Dauto%3Fsec%3D1661051088%26t%3D66856c9f40dffe887a63f02f856d8637&thumburl=https%3A%2F%2Fimg0.baidu.com%2Fit%2Fu%3D3798217922%2C3880088897%26fm%3D253%26fmt%3Dauto%26app%3D120%26f%3DJPEG%3Fw%3D889%26h%3D500"));
excelWriter.fill(map, writeSheet0);
excelWriter.finish();
System.out.println(System.currentTimeMillis() - begin);
}
}
easyExcel maven版本
<!--easyExcel-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.1.0</version>
</dependency>如果是多个sheet页制作,需要多个 WriteSheet 信息
WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build(); 信息,You can change the numbers in it,多个sheetPage parameter information is not public,
代码如下
WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build();
//开启自动换行,Word wrap means writing one line at a timelistData is regenerated with a blank line,此选项默认是关闭的,需要提前设置为true
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
FillConfig fillConfig2 = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
//excelWriter.fill(paramValueMapListNew, fillConfig, writeSheet);
excelWriter.fill(new FillWrapper("user", paramValueMapListNew), fillConfig, writeSheet0);
excelWriter.fill(new FillWrapper("site", paramValueMapListNew), fillConfig, writeSheet0);
excelWriter.fill( paramValueMapListNew, fillConfig2, writeSheet0);
Map<String, Object> map1 = new HashMap<>();
map1.put("title", "Drug recall record sheet");
map1.put("total", 1000);
map1.put("time", "2022年07月22日13:28:28");
map1.put("image", new URL("https://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fimg.jj20.com%252Fup%252Fallimg%252F4k%252Fs%252F02%252F2109242306111155-0-lp.jpg%26refer%3Dhttp%253A%252F%252Fimg.jj20.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Dauto%3Fsec%3D1661051088%26t%3D66856c9f40dffe887a63f02f856d8637&thumburl=https%3A%2F%2Fimg0.baidu.com%2Fit%2Fu%3D3798217922%2C3880088897%26fm%3D253%26fmt%3Dauto%26app%3D120%26f%3DJPEG%3Fw%3D889%26h%3D500"));
excelWriter.fill(map1, writeSheet0);
WriteSheet writeSheet1 = EasyExcel.writerSheet(1).build();
excelWriter.fill(new FillWrapper("user", paramValueMapListNew), fillConfig, writeSheet1);
excelWriter.fill(new FillWrapper("site", paramValueMapListNew), fillConfig, writeSheet1);
excelWriter.fill( paramValueMapListNew, fillConfig2, writeSheet1);
map1.put("image", new URL("https://image.baidu.com/search/down?tn=download&ipn=dwnl&word=download&ie=utf8&fr=result&url=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fimg.jj20.com%252Fup%252Fallimg%252F4k%252Fs%252F02%252F2109242306111155-0-lp.jpg%26refer%3Dhttp%253A%252F%252Fimg.jj20.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Dauto%3Fsec%3D1661051088%26t%3D66856c9f40dffe887a63f02f856d8637&thumburl=https%3A%2F%2Fimg0.baidu.com%2Fit%2Fu%3D3798217922%2C3880088897%26fm%3D253%26fmt%3Dauto%26app%3D120%26f%3DJPEG%3Fw%3D889%26h%3D500"));
excelWriter.fill(map1, writeSheet1);边栏推荐
猜你喜欢
随机推荐
私域增长 | 私域会员:9大连锁行业15个案例集锦
ESP8266-Arduino programming example-I2C device address scan
C# CLI(公共语言基础结构)
Experience Sharing | Tips for Writing Easy-to-Use Online Product Manuals
【体系结构 一 概述】
线程池 ThreadPoolExecutor 详解
知识库对企业的意义
“加价”都换不来安全保障,雷克萨斯LM之殇,到底是谁的错?
要卖课、要带货,知识付费系统帮你一步搞定!
ESP8266-Arduino编程实例-LittleFS及数据上传
第二增长曲线 | 企业创新突破停滞困境的驱动指南
接口测试工具之Postman详解
一些投资的底线
Gesture password unlock WeChat applet project source code
Experience Sharing | Tips for Writing Easy-to-Use Online Product Manuals
2.5w字 + 36 张图爆肝操作系统面试题 学不吐你
树上启发式合并小结
OpenCV - 图像二值化处理 腐蚀膨胀 边缘检测 轮廓识别
HbuilderX打包app,Hbuilder怎么打包app,H5打包成app,H5怎么打包成app「建议收藏」
regular expression









