当前位置:网站首页>jfinal hutool工具 excelUtil ZipUtil实现导出excel并压缩文件
jfinal hutool工具 excelUtil ZipUtil实现导出excel并压缩文件
2022-04-21 06:29:00 【有梦想的小弱鸡】
导入jar
<!-- Hutool超级工具类 http://hutool.mydoc.io/ -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
//获取list
List<VideoLearnLog> videoLearnLogs= VideoLearnLog.dao.
template("videoLearnLog.find", select).find();
//excel
String fileUuid = UuidKit.getUUIDNoMinus();
//项目路径 给随机文件名 打jar用
String path = (PathKit.getWebRootPath() + "/"+fileUuid+"/model/").replace("\\", "/");
//excel第一行
String[] headers = {
"用户", "视频", "方案", "观看秒数", "学习时间","状态"};
Collection coll = new ArrayList();
//放入
List<String> row = CollUtil.newArrayList(headers);
coll.add(row);
//循环
for (int i = 0; i < videoLearnLogs.size(); i++) {
Integer total_learn_second = busEducationVideoLearnLogs.get(i).get("total_learn_second");
String total_learn_secondStr=String.valueOf(total_learn_second);
String[] colums ={
videoLearnLogs.get(i).get("uname"),videoLearnLogs.get(i).get("vtitle") ,
videoLearnLogs.get(i).get("epname"),
total_learn_secondStr,
videoLearnLogs.get(i).getStudyTime(),videoLearnLogs.get(i).get("state_name")};
//存入
List<String> row2 = CollUtil.newArrayList(colums);
coll.add(row2);
//将图片下载path目录下 img为oss图片下载地址
String img= downloadImage(path,videoLearnLogs.get(i).getImg(), videoLearnLogs.get(i).getName(), fileUuid);
}
//生成excel
String excelName="视频记录";
//headers数
Integer count=6;
downloadExcel(path,excelName,count,coll);
//当前目录下 压缩成jar
File file = ZipUtil.zip(PathKit.getWebRootPath() + "/"+fileUuid+"/model");
//给前端
renderFile(file);
//图片下载 img为oss图片下载地址
public static String downloadImage(String path,String img, String name, String fileUuid) {
try {
URL httpurl = new URL(img);
String newName = null;
File f = new File(path + newName);
FileUtils.copyURLToFile(httpurl, f);
return path + newName;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
//excel下载
public static void downloadExcel(String path, String excelName, Integer count, Collection coll) {
List<List<String>> rows = CollUtil.newArrayList(coll);
ExcelWriter writer = ExcelUtil.getWriter(path + excelName + ".xlsx");
// 合并单元格后的标题行,使用默认标题样式
writer.merge(count - 1, excelName);
// 一次性写出内容,使用默认样式,强制输出标题
writer.write(rows, true);
// 关闭writer,释放内存
writer.close();
}



版权声明
本文为[有梦想的小弱鸡]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq53167889/article/details/115202377
边栏推荐
- Learn Ruixin micro rk3399pro record (10)
- 删除迅雷看看文件夹右键菜单的卸载残留
- Dpdk problem analysis: dpdk-20.11 ice 100g network card RSS_ Invalid hash configuration
- 【论文精读】Deep Surface Normal Estimation with Hierarchical RGB-D Fusion
- VMWare vSphere Failed to create object
- postgres uuid_ generate_ v1() does not exist
- Udevd retrieves the kernel module and loads the demo
- Blood cases caused by dpdk program startup sequence
- Method and principle of obtaining the CPU core of the last execution of the process
- 《21天实战caffe》1-7天学习笔记一
猜你喜欢

在ensp上配置安全策略

基于UnityGameFramework框架的AssetBundle打包

虚幻引擎之多线程渲染机制

Database splitting under microservice architecture

效率工具|专用截图辅助软件PureRef

程序启动顺序引发的血案之 dpdk 进程死锁

Unable to resolve dependency for ':app@debug/compileClasspath': Could not download mapsforge-map.jar

Installing deepstream on TX2

AWD平台搭建–Cardinal

Hardware codec acceleration CSI interface camera on TX2
随机推荐
There are three ways of asynchronous RPC: asynchronous call, asynchronous listening and callback call
WordPress修改上传文件大小限制
IDEA配置servlet出现404问题解决
Hardware codec acceleration CSI interface camera on TX2
网络攻防安全学习平台-上传关3
The use of NuMA by dpdk and the basis of performance tuning under multi NUMA architecture
Previous blog posts in blog Park
dpdk-16.04 监听 uio 文件检测中断的示例 demo 与内部实现解析
C语言版:循环链表的建立
Build a deep learning server and environment configuration from scratch
Unity 射击游戏的准星位置
udevd 检索内核模块并加载的 demo
dpdk程序启动顺序引发的血案
Porting ucosiii to ucosiii - task suspend / restore / hook / (nanny tutorial)
PowerShell - delay start sleep
【眼见非实-Bugku CTF】
Lua programming -- Notes
虚幻引擎之使用LoadClass加载蓝图类
3D-MAX之Shader工具(描边)
常用的MySQL语句